1. 程式人生 > >python編程快速上手之第15章實踐項目參考答案(17.7.3)

python編程快速上手之第15章實踐項目參考答案(17.7.3)

lane width ima font height 開始 users nco window

#! 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)