Skip to content

Instantly share code, notes, and snippets.

@jeremy886
Created June 3, 2017 07:40
Show Gist options
  • Save jeremy886/c0787beadee127ae1280d1d9ec232593 to your computer and use it in GitHub Desktop.
Save jeremy886/c0787beadee127ae1280d1d9ec232593 to your computer and use it in GitHub Desktop.
draw chinese text using true type font
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