From 065f59f04df0cbff7c8e6c9fa5ac443ef4079253 Mon Sep 17 00:00:00 2001 From: Shuge Lee Date: Wed, 16 Jan 2013 11:52:55 +0800 Subject: [PATCH] Fixed draw_text/draw_text.py on Ubuntu --- Demos/draw_text/draw_text.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Demos/draw_text/draw_text.py b/Demos/draw_text/draw_text.py index 236ee8f3d..b63c914a6 100644 --- a/Demos/draw_text/draw_text.py +++ b/Demos/draw_text/draw_text.py @@ -1,21 +1,20 @@ #!/usr/bin/env python +#-*- coding:utf-8 -*- import os import sys -from PIL import Image, ImageDraw, ImageFont +from PIL import Image +from PIL import ImageDraw +from PIL import ImageFont PWD = os.path.dirname(os.path.realpath(__file__)) parent_path = os.path.dirname(PWD) -BLACK = "#ffffff" -WHITE = "#000000" +BLACK = "#000000" +WHITE = "#ffffff" -fg_color = WHITE -bg_color = BLACK - - -canvas_w, canvas_h = 180, 50 +canvas_w, canvas_h = 250, 50 im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE) draw = ImageDraw.Draw(im=im) @@ -23,15 +22,19 @@ draw = ImageDraw.Draw(im=im) left_top_x, left_top_y = 10, 10 begin = left_top_x, left_top_y -text = "hello world" +text = u"hello world 中文" if sys.platform == "darwin": filename = "/Library/Fonts/Microsoft/Times New Roman Bold.ttf" elif sys.platform == "win32": - #filename = "C:/Windows/Fonts/timesbd.ttf" filename = "timesbd.ttf" +elif sys.platform == "linux2": + # this script required wqy truetype font, + # install it on Debian/Ubuntu: apt-get install ttf-wqy-microhei + filename = "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc" else: - raise Exception + raise NotImplementedError + font_size = 26 font = ImageFont.truetype(filename=filename, size=font_size)