PIL Draw.text 和较低分辨率
我有以下 PIL 代码来打印图像中的文本
import os, sys
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
img = Image.open("one.jpg")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",27)
draw.text((100, 100), "test test test", font=font)
img.save("out.jpg")
这适用于 one.jpg 文件。然而,在另一个名为two.jpg 的测试文件上,它不会打印任何内容。据我所知,两个文档之间的唯一区别是two.jpg 的分辨率较低。文件 one.jpg 为 200x200 dpi,two.jpg 为 60x60 dpi。
我怎样才能让draw.text在较低的分辨率下工作?
谢谢,
I have the following PIL code to print text in an image
import os, sys
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
img = Image.open("one.jpg")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf",27)
draw.text((100, 100), "test test test", font=font)
img.save("out.jpg")
This works on one.jpg file. However on another test file called two.jpg, it doesn't print anything. From what I see, the only difference between two documents is the lower resolution on two.jpg. The file one.jpg is 200x200 dpi, two.jpg is 60x60 dpi.
How can I get draw.text to work in lower res?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要指定文本的颜色:
You need to specify a color for the text: