I'm currently using ImageMagick's convert command to create text preview (.png) from .ttf font file. Overall, it's better in auto text positioning despite it failed to read some valid .ttf file sometimes. The speed is not great but acceptable.
PIL's ImageFont looks like is not good at text aligning, often prints bottom-left corner of first character outside canvas.
Does anyone know any better choices beside the above two? I wonder what tech is needed to power the text preview part on sites like myfonts.com with so heavy traffic.
EDIT
Example of PIL Font failed to draw fonts correctly. Font used in the example is Hanford script
import Image, ImageDraw, ImageFont
font = ImageFont.truetype('HANFORD_.TTF', 122)
text_width, text_height = font.getsize('Hanford script')
print text_width, text_height
>>> 833 47
img = Image.new('RGBA', (text_width, text_height))
draw = ImageDraw.Draw(img)
draw.text((0, 0), 'Hanford script', font=font, fill=(0, 0, 0))
img.save('output.png')
The output image only contains upper half of "Hanford script".
I tried with imagemagick's convert command:
convert -font "HANFORD_.TTF" -background transparent -gravity center -size 830x80 label:'Hanford script' output.png
The output image was same as what I got by PIL.
It's not the only font that PIL or imagemagick cannot get correct text size. With some other fonts, like Ginga, they just amplify text height which result in upper half of output images are blank. Anyone knows the reason?