[英]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 ) 这是生成的图像: img http://www.freeimagehosting.net/image.php?976a0d3eaa.png (由于某种原因,我无法在SO上显示它,因此链接为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. 编辑:balpha评论后,我决定尝试另一种字体。 I'm only interested in ttf fonts, so I tried with another one, and it worked.
我只对ttf字体感兴趣,所以我尝试了另一种字体,并且效果很好。 This is kind of strange.
这有点奇怪。 The original font I tried to run this with is Beautiful ES .
我尝试使用此字体运行的原始字体是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; PIL使用freetype2库,因此很可能是字体文件有问题。 for example, it could have bad metrics defined (eg see the OS/2 related ones opening the font with FontForge).
例如,它可能定义了错误的度量标准(例如,与OS / 2相关的度量标准使用FontForge打开字体)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.