合并图片

合并图片

十月 03, 2020
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sys
from PIL import Image

width = 0
height = 0
for imageFile in sys.argv[1:]:
with Image.open(imageFile) as im2:
width = width + im2.size[0]
height = max(height, im2.size[1])
im = Image.new('RGB', (width, height))
width = 0
height = 0
for imageFile in sys.argv[1:]:
with Image.open(imageFile) as im2:
im2_width = im2.size[0]
im2_height = im2.size[1]
im.paste(im2.crop((0, 0, im2_width, im2_height)), (width, 0, width + im2_width, im2_height))
width = width + im2_width
im.save('result.jpeg', 'JPEG')