
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 0.89 KB | hits: 16 | expires: Never
PIL problems: failed in loading any font library and using unicode
# -*- coding: utf-8 -*-
import sys
from PIL import Image
import ImageFont, ImageDraw
text = sys.argv[1]
if not isinstance(text, unicode):
text = text.decode('gbk')
filename = sys.argv[2]
image = Image.new("RGBA", (100, 100), (255,255,255))
usr_font = ImageFont.truetype("simsun.ttc", 50) #In fact, it can't load any font lib.
d_usr = ImageDraw.Draw(image)
d_usr = d_usr.text((10, 10), text, fill = "blue", font=usr_font) #error when text is Chinese
image.save(filename)
#! /usr/bin/python
# -*- coding: utf-8 -*-
import Image
import ImageDraw
import ImageFont
ttfont = ImageFont.truetype ('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 20)
text = u'我能有乾酪?'
image = Image.new ('RGB', (256, 128), 0xffffff);
ImageDraw.Draw (image).text ( (20, 20), text, font = ttfont, fill = (0, 0, 0) )
image.save ('chinese.jpg')