设计需求:
现在要制作一系列展品的小标签,使用一份相同的背景,改动的仅是文字内容
设计环境:
Adobe Photoshop CC 2017
Python 3.X
技巧思路:
用Photoshop自带的功能将每个图层输出为PNG格式到某一文件夹
使用python的PIL的Image模块,批量合成
根据此次的文字居中要求,合成时的坐标经过计算(应该是前景的左上角在背景上的坐标,此坐标系的原点为左上角)
Python 3.X 源代码:
from PIL import Image
def mergePNG(index,background):
tmpImg=Image.new('RGB',background.size,(0,0,0))#这里的0是RGB的参数
tmpImg.paste(background)
foreground=Image.open('foreground ('+str(index)+').png')
tmpImg.paste(foreground, (int((background.size[0]-foreground.size[0])/2),int((background.size[1]-foreground.size[1])/2)), foreground)
#tmpImg.show()
tmpImg.save('merge'+str(index)+'.jpg')
background=Image.open("background.png")
for i in range(1,23):
mergePNG(i,background)#此处的文件名是直接在win10下全选后批量修改得到的,所以会有括号,虽然我很想知道能不能变成下划线那种格式
供参考,请勿转载