Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import sys
- from PIL import Image, ImageDraw, ImageFont
- text = "在流行VPN服务NordVPN证实遭到入侵但披露100%滞后的新闻传出之后,为什么不要使用VPN服务的争论再起。VPN是一种代理服务器,服务商能看到用户的所有流量"
- font = ImageFont.truetype(os.path.join("", "SourceHanSansCN-Regular.ttf"), 18)
- im = Image.new("RGB", (1000, 200), (255,255,255))
- draw = ImageDraw.Draw(im)
- draw.text((20, 20), text, fill=(0, 0, 0), font=font)
- p = re.compile(r'([\u4e00-\u9fa5])')
- str_list = p.split(text)
- words = [w for w in str_list if len(w.strip()) > 0]
- width = 20
- for word in words:
- draw.text((width, 80), word, fill=(0, 0, 0), font=font)
- width += font.getsize(word)[0]
- im.save("testfont.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement