上班摸鱼写的,不多说了,直接上脚本
#coding=utf-8 from PIL import Image from PIL import ImageDraw from PIL import ImageFont txt = '给我也整一个' font = ImageFont.truetype('simsun.ttc',9) #9为字体大小 im_path = 'gei.png' #原图路径 im = Image.open(im_path) width, height = im.size newImg = Image.new("RGBA",(width, height),(10,10,10)) #背景色rgb,偏黑显示好一些 x=0 for i in range(0,height,9): #需要与字体大小一致 for j in range(0,width,9): #需要与字体大小一致 a,b,c=im.getpixel((j,i)) draw = ImageDraw.Draw(newImg) draw.text( (j,i), unicode(txt[x%(len(txt)):x%(len(txt))+3],'UTF-8'), fill=(a,b,c),font=font) x+=3 del draw newImg.save('00.png','PNG')
效果图以及字体文件:
下载地址:字符画.zip