I started with the script in this nice answer. It works just fine for "RGB", but the 8-bit gray scale "L" and 1-bit black/white "1" PIL image modes just appear black. What am I doing wrong?
from PIL import Image, ImageDraw, ImageFont
import numpy as np
w_disp = 128
h_disp = 64
fontsize = 32
text = u"你好!"
for imtype in "1", "L", "RGB":
image = Image.new(imtype, (w_disp, h_disp))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf", fontsize)
w, h = draw.textsize(text, font=font)
draw.text(((w_disp - w)/2, (h_disp - h)/2), text, font=font)
image.save("NiHao! 2 " + imtype + ".bmp")
data = np.array(list(image.getdata()))
print data.shape, data.dtype, "min=", data.min(), "max=", data.max()
Output:
(8192,) int64 min= 0 max= 0
(8192,) int64 min= 0 max= 0
(8192, 3) int64 min= 0 max= 255