Created
June 3, 2017 07:40
-
-
Save jeremy886/c0787beadee127ae1280d1d9ec232593 to your computer and use it in GitHub Desktop.
draw chinese text using true type font
This file contains 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
from PIL import ( | |
Image, | |
ImageDraw, | |
ImageFont, | |
) | |
#SIZE = (100, 100) | |
base = Image.open('images/lena.png').convert('RGBA') | |
text = Image.new('RGBA', base.size, (255, 255, 255, 0)) | |
# Chinese Fonts | |
# /Library/Fonts/SourceHanSans.ttc | |
# /Library/Fonts/SourceHanSerif.ttc | |
font = ImageFont.truetype('/Library/Fonts/SourceHanSans.ttc', 120) | |
d = ImageDraw.Draw(text) | |
d.text((10,10), "你好", font=font, fill=(255,255,255,128)) | |
# draw text, full opacity | |
d.text((10,150), "龵目", font=font, fill=(255,255,255,255)) | |
out = Image.alpha_composite(base, text) | |
out.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment