简体   繁体   中英

How can I find out why PIL isn't drawing the font correctly?

Here's the code I'm using:

from PIL import Image
import ImageFont, ImageDraw
import sys
import pdb

img = Image.new("RGBA",(300,300))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(sys.argv[1],30)
draw.text((0,100),"world",font=font,fill="red")
del draw
img.save(sys.argv[2],"PNG")

and here's the image that results: img http://www.freeimagehosting.net/image.php?976a0d3eaa.png ( for some reason, I can't make it show on SO, so the link is http://www.freeimagehosting.net/image.php?976a0d3eaa.png )

The thing is, I don't understand why it isn't drawing the font correctly? I should be able to read the word "world" off of it. It's like the picture's been cut in half or something. Does anyone have any clue?

EDIT: after balpha's comment, I decided to try another font. I'm only interested in ttf fonts, so I tried with another one, and it worked. This is kind of strange. The original font I tried to run this with is Beautiful ES . I'm curious if you guys can reproduce the same image on your computers, and if you happen to know the reason for why that is.

PIL uses the freetype2 library, so most possibly it is an issue with the font file; for example, it could have bad metrics defined (eg see the OS/2 related ones opening the font with FontForge).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM