简体   繁体   English

我如何找出PIL无法正确绘制字体的原因?

[英]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.

相关问题 如何找出使用PIL函数导致内存错误的原因? - How can I find out why using PIL functions is resulting in a memory error? 为什么我的图像无法在我的平台游戏中正确绘制? - Why isn't my image drawing correctly in my platformer? 为什么来自PIL的ImageFont无法在Python中加载印尼字体? - Why ImageFont from PIL can't load Indonesia font in Python? 如何在Django中加载用于PIL的静态字体文件? - How can I load a static font file for use with PIL in Django? 无法找出为什么 MQTT python 应用程序没有订阅或接收消息 - Can't find out why MQTT python app isn't subscribing or receiving messages 我无法导入某些库,包括 Pil,这是为什么呢? - I can't import some libraries, including Pil, why is that? 使用嵌套for循环在Pygame中创建矩形网格,为什么绘制不正确? - Using a nested for loop to create a grid of rectangles in Pygame, why isn't it drawing correctly? Pygame 没有移动我的矩形,我不知道为什么? - Pygame isn't moving my rectangle and I can't figure out why? 我不知道为什么我的makemigrations无法在Django中工作,它显示以下错误 - I can't figure out why my makemigrations isn't working in django,its showing following error 我不知道为什么我的 web 抓取代码不起作用 - I can't figure out why my web scraping code isn't working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM