Do any Python alternatives exist for overlaying an image with text? I tried with PIL/Pillow, but the output is really grainy and artifacted.
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.
Try changing the image quality:
img.save('sample-out123.jpg', quality=95)
Or, save as a PNG.
img.save('sample-out123.png')