PIL居中对齐文本

2020-05-27  本文已影响0人  空口言_1d2e
from PIL import Image, ImageDraw 

W, H = (300,200) 
msg = "hello" 

im = Image.new("RGBA",(W,H),"yellow") 
draw = ImageDraw.Draw(im) 
w, h = draw.textsize(msg) 
draw.text(((W-w)/2,(H-h)/2), msg, fill="black") 

im.save("hello.png", "PNG") 

Python图像处理PIL各模块详细介绍

上一篇下一篇

猜你喜欢

热点阅读