I'm trying to create PNGs of letters from the fonts on my system. Seems to work okay with TrueType fonts (.ttf) but not OpenType (.otf). The images formed are the same size but the actual letters appear much smaller with OpenType - see below.
I'm using the ImageFont module from the Python Imaging library. There doesn't seem to be a way to distinguish between the two formats; both are imported with
ImageFont.truetype(filename, size)
What am I missing?
example code:
try:
font = ImageFont.truetype(name, size)
for text in string.letters:
size2 = font.getsize(text)
im = Image.new('RGBA', size2, (0, 0, 0, 0))
draw = ImageDraw.Draw(im)
draw.text((0, 0), text, font=font, fill="black")
if not os.path.exists(name[:-4]):
os.makedirs(name[:-4])
if text in string.lowercase:
im.save(name[:-4]+".png")
else:
im.save(name[:-4]+"_u.png")
except:
pass
Images of Adobe Caslon and Arial for comparsion.