环境要求
- 安装python3环境
- 安装pillow图片处理库
开发前准备
推荐使用conda 创建python环境
conda create -n pr python=3.8 # 创建环境 conda activate pr # 进入环境
安装pillow图片处理库
pip install pillow
准备一张证件照(一寸照)
下载地址:https://github.com/kxsv/id-photo-demo/blob/main/images/test.jpeg
准备设计好的6寸模板图
下载地址:https://github.com/kxsv/id-photo-demo/blob/main/images/print-bg/295-413.png
代码实现
from PIL import Image import os def print_main(): id_photo = Image.open(os.getcwd() + '/test.jpeg') # 一寸证件照 print_bg = Image.open(os.getcwd() + '/295-413.png') # 获取排版背景图 print_bg.paste(id_photo, (120, 180)) print_bg.paste(id_photo, (435, 180)) print_bg.paste(id_photo, (750, 180)) print_bg.paste(id_photo, (1065, 180)) print_bg.paste(id_photo, (1380, 180)) print_bg.paste(id_photo, (120, 613)) print_bg.paste(id_photo, (435, 613)) print_bg.paste(id_photo, (750, 613)) print_bg.paste(id_photo, (1065, 613)) print_bg.paste(id_photo, (1380, 613)) path = os.getcwd() + "/res-print.jpeg" print_bg.save(path) # 保存排版照 print_bg.show() # 显示 if __name__ == '__main__': print_main()
查看排版照
完整代码下载
https://github.com/kxsv/id-photo-demo
标签:bg,paste,python,photo,613,print,证件照,排版,id From: https://www.cnblogs.com/kxsv/p/16824546.html