#Collection of calligraphy characters
import os
from PIL import Image
if __name__ == '__main__':
im_list = []
path = r"C:\Users\Administrator\Desktop\724"
pathlist = os.listdir(path)
for fn in reversed(pathlist):
if fn.endswith('.jpg'):
im_list.append(Image.open(path + os.sep + fn))
width = 0
height = 0
for img in im_list:
# 单幅图像尺寸
w, h = img.size
width += w
# 取最大的宽度作为拼接图的宽度
height= max(height, h)
# 创建空白长图
result = Image.new(im_list[0].mode, (width, height), 0xffffff)
# 拼接图片
width = 0
for img in im_list:
w, h = img.size
# 图片水平居中
result.paste(img, box=(width,round(height / 2 - h / 2)))
width += w
# 保存图片
result.save(r'C:\Users\Administrator\Desktop\拼接长图.jpg')