#! Python3#Encoding:utf-8ImportOs,docx fromPILImportImage, Imagedraw fromPILImportImagefontos.chdir ('C:\\users\\administrator\\python35-32\\test\\kuaisu') Guests= Open ('Guests.txt') Logoim= Image.open ('flowerlogo.jpg') width, height=Logoim.sizelogoim= Logoim.resize ((166,108)) #重新定义LOGO大小 forIinchGuests:im= Image.new ('RGBA', (230, 362),' White') #生产白色卡片 Draw=Imagedraw.draw (IM) draw.rectangle ((1, 1, 228, outline=),'Black') #画黑色边框 N= (230-len (i) *12.5)/2 #计算开始位置 to center the guest nameft= Imagefont.truetype ("C:\\windows\\fonts\\brushsci. TTF", 13) Draw.text (13,30), U"It would is a pleasure to the", Font = ft, fill ='Blue') ft= Imagefont.truetype ("C:\\windows\\fonts\\engr. TTF", 15) Draw.text (n,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 Programming Quick Start 15th Chapter Practical Project Reference Answer (17.7.3)