python编程快速上手之第15章实践项目参考答案(17.7.3)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)的主要内容,如果未能解决你的问题,请参考以下文章
python编程快速上手之第15章实践项目参考答案(17.7.3)
python编程快速上手之第10章实践项目参考答案(11.11.2)