mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-02 03:20:11 +03:00
Fixed draw_text/draw_text.py on Ubuntu
This commit is contained in:
parent
acdda34589
commit
065f59f04d
|
@ -1,21 +1,20 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
#-*- coding:utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import sys
|
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__))
|
PWD = os.path.dirname(os.path.realpath(__file__))
|
||||||
parent_path = os.path.dirname(PWD)
|
parent_path = os.path.dirname(PWD)
|
||||||
|
|
||||||
BLACK = "#ffffff"
|
BLACK = "#000000"
|
||||||
WHITE = "#000000"
|
WHITE = "#ffffff"
|
||||||
|
|
||||||
fg_color = WHITE
|
canvas_w, canvas_h = 250, 50
|
||||||
bg_color = BLACK
|
|
||||||
|
|
||||||
|
|
||||||
canvas_w, canvas_h = 180, 50
|
|
||||||
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
im = Image.new(mode="RGB", size=(canvas_w, canvas_h), color=WHITE)
|
||||||
|
|
||||||
draw = ImageDraw.Draw(im=im)
|
draw = ImageDraw.Draw(im=im)
|
||||||
|
@ -23,15 +22,19 @@ draw = ImageDraw.Draw(im=im)
|
||||||
left_top_x, left_top_y = 10, 10
|
left_top_x, left_top_y = 10, 10
|
||||||
begin = left_top_x, left_top_y
|
begin = left_top_x, left_top_y
|
||||||
|
|
||||||
text = "hello world"
|
text = u"hello world 中文"
|
||||||
|
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
filename = "/Library/Fonts/Microsoft/Times New Roman Bold.ttf"
|
filename = "/Library/Fonts/Microsoft/Times New Roman Bold.ttf"
|
||||||
elif sys.platform == "win32":
|
elif sys.platform == "win32":
|
||||||
#filename = "C:/Windows/Fonts/timesbd.ttf"
|
|
||||||
filename = "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:
|
else:
|
||||||
raise Exception
|
raise NotImplementedError
|
||||||
|
|
||||||
font_size = 26
|
font_size = 26
|
||||||
font = ImageFont.truetype(filename=filename, size=font_size)
|
font = ImageFont.truetype(filename=filename, size=font_size)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user