这篇文章上次修改于 563 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
python 多张图片合并到一张
## 多张图片合并到一张(垂直)
import sys
from PIL import Image
images = [Image.open(x) for x in ['./imgs/1_page1.jpg', './imgs/1_page2.jpg', './imgs/1_page3.jpg', './imgs/1_page4.jpg', './imgs/1_page5.jpg', './imgs/1_page6.jpg', './imgs/1_page7.jpg', './imgs/1_page8.jpg', './imgs/1_page9.jpg']]
widths, heights = zip(*(i.size for i in images))
max_width = max(widths)
total_height = sum(heights)
new_im = Image.new('RGB', (max_width, total_height))
y_offset = 0
for im in images:
new_im.paste(im, (0,y_offset))
y_offset += im.size[1]
new_im.save('test.jpg')
没有评论