Skip to content

Instantly share code, notes, and snippets.

@dannvix
Created March 24, 2012 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dannvix/2180790 to your computer and use it in GitHub Desktop.
Save dannvix/2180790 to your computer and use it in GitHub Desktop.
Paint text on given image with PIL
#!/usr/bin/env python
#-*- encoding: utf8
# sudo easy_install PIL
import Image
import ImageFont
import ImageDraw
image = Image.open("image.png")
image_width, image_height = image.size
font_path = '/Library/Fonts/ヒラギノ角ゴ Pro W6.otf';
font = ImageFont.truetype(font_path, 14, encoding='unic')
text = '這是測試圖片 This is test image'.decode('utf-8')
text_width, text_height = font.getsize(text)
draw = ImageDraw.Draw(image)
draw.text(((image_width - text_width), (image_height - text_height)), text, font=font, fill=(255, 255, 255))
image.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment