用Python【批量】生产【电子奖状】的方法请查收! |
您所在的位置:网站首页 › 150k的图片像素多大比例好看些 › 用Python【批量】生产【电子奖状】的方法请查收! |
流程: 1.用PS设计好荣誉证书模板,在姓名处留白 2.批量生产 一、用PS设计好荣誉证书模板 2.批量生产 ''' 批量生产电子奖状 ''' from docx.shared import Pt, RGBColor from PIL import Image,ImageDraw,ImageFont old_img = Image.open(r"荣誉证书模板.png")#导入证书模板 draw = ImageDraw.Draw(old_img) # 设置图片文字,字体,大小,颜色 newfont=ImageFont.truetype('c:Users/86136/AppData/Local/Microsoft/Windows/Fonts/HGH_CNKI.TTF',120) newcolor = RGBColor(175,137,84) #通过RGB设置学生名字的颜色 with open("student.txt", "r",encoding = 'utf-8') as f: #循环制造 for line in f.readlines(): line = line.strip('\n') #去掉列表中每一个元素的换行符 old_img = Image.open(r"荣誉证书模板.png") draw = ImageDraw.Draw(old_img) # 设置图片文字,字体类型,以及字体大小,颜色 newfont=ImageFont.truetype('c:Users/86136/AppData/Local/Microsoft/Windows/Fonts/HGH_CNKI.TTF',120) draw.text((850,750),line,font=newfont,fill = newcolor) save_adress = str(line) + '.png' old_img.save(save_adress) print(line + "荣誉证书制作完成")三、成果展示 四、制作过程中的报错经验 1.报错UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa2 in position 30: illega 解决:读取txt时,添加encoding = ‘utf-8’,且txt命名方式只能为英文字母不能为中文。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |