首页 > 代码库 > python编程快速上手之第15章实践项目参考答案(17.7.3)
python编程快速上手之第15章实践项目参考答案(17.7.3)
#! python3 # encoding: UTF-8 import os,docx from PIL import Image, ImageDraw from PIL import ImageFont os.chdir(‘C:\\Users\\Administrator\\Python35-32\\test\\kuaisu‘) guests = open(‘guests.txt‘) logoIm = Image.open(‘flowerlogo.jpg‘) width, height = logoIm.size logoIm = logoIm.resize((166,108)) #重新定义LOGO大小 for i in guests: im = Image.new(‘RGBA‘, (230, 362), ‘white‘) #生产白色卡片 draw = ImageDraw.Draw(im) draw.rectangle((1, 1, 228, 360), outline=‘black‘) #画黑色边框 n= (230-len(i)*12.5)/2 #计算开始位置,让客人名字居中 ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\BRUSHSCI.TTF", 13) draw.text((13,30), u"It would be a pleasure to have the company of",font = ft, fill = ‘blue‘) ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\ENGR.TTF", 15) draw.text((n,80), i , font = ft, fill = ‘black‘) ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\BRUSHSCI.TTF", 15) draw.text((19,130), u"At 11010 Memory lane on the evening of",font = ft, fill = ‘blue‘) ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\Calibri.TTF", 15) draw.text((72,180), u"April 1st",font = ft, fill = ‘blue‘) ft = ImageFont.truetype("C:\\WINDOWS\\Fonts\\BRUSHSCI.TTF", 15) draw.text((72,230), u"at 7 o’clock",font = ft, fill = ‘blue‘) im.paste(logoIm, (20, 252)) #加上LOGO name = str("sitcard("+ i.strip(‘\n‘) + ").png") #保存为客户名字 im.save(name)
python编程快速上手之第15章实践项目参考答案(17.7.3)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。