Created
March 24, 2012 10:02
-
-
Save dannvix/2180790 to your computer and use it in GitHub Desktop.
Paint text on given image with PIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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