Skip to content Skip to sidebar Skip to footer

Drawing Text With Pil Does Not Work On All Images

I'm trying to draw text on images with PIL. However, I can see text on certain images only. A lot of png's don't work, such as this one: http://r0k.us/graphics/kodak/kodim16.html C

Solution 1:

I think you just got the x and y coordinates the wrong way around and were trying to write 600 pixels down an image that is 512 pixels tall:

#!/usr/bin/env python3import PIL
from PIL import Image, ImageFont, ImageDraw

im1=Image.open('start.png')

# Drawing the text on the picture
font = ImageFont.truetype('/Library/Fonts/Herculanum.ttf', 100)
draw = ImageDraw.Draw(im1)
draw.text((50, 200), 'OMG!', (255,0,255), font=font)

# Save the image with a new name
im1.save('result.png')

enter image description here

Post a Comment for "Drawing Text With Pil Does Not Work On All Images"