简体   繁体   English

PIL /枕头的替代方案,用于在图像上覆盖文字

[英]Alternatives to PIL/Pillow for overlaying an image with text

Do any Python alternatives exist for overlaying an image with text? 是否存在任何Python替代方案可用于在图像上覆盖文字? I tried with PIL/Pillow, but the output is really grainy and artifacted. 我尝试使用PIL / Pillow,但输出确实有颗粒感和失真。

Here is my code: 这是我的代码:

from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw

img = Image.open("image.jpg")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("Comic Sans MS.ttf", 24)
draw.text((150, 20),"Sample Text",(170,14,179), font=font)
img.save('sample-out123.jpg')

and the output: 和输出:

在此处输入图片说明

You can see artifacting around the text as well as a light purple glow. 您会看到文本周围的伪影以及淡紫色的光。

This is a known problem with JPEG images . 这是JPEG图像已知问题

Try changing the image quality: 尝试更改图像质量:

img.save('sample-out123.jpg', quality=95)

Or, save as a PNG. 或者,另存为PNG。

img.save('sample-out123.png')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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