-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpic_connect.py
40 lines (31 loc) · 956 Bytes
/
pic_connect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# coding=utf8
import os
from PIL import Image
def connect(pics: list):
ifs = [Image.open(fn) for fn in pics]
width = 300
height = 0
for img in ifs:
if width < img.size[0]:
width = img.size[0]
print(img, img.size)
for img in ifs:
# 图像放大率
ratio = width/img.size[0]
height = height + ratio*img.size[1]
im = Image.new("RGB", (width, int(height)))
y = 0
for img in ifs:
ratio = width/img.size[0]
img_scaled = img.resize((width, int(ratio*img.size[1])))
im.paste(img_scaled, (0, int(y)))
y = y + img.size[1]*ratio
im.save("output3.jpg")
# print( , " *size:", ifs[0].size)
if __name__ == "__main__":
pics = [fn for fn in os.listdir(
".") if fn[0].isdigit() and fn.endswith(".jpg")]
pics = ['1.jpg', '2.jpg', '3.jpg', '4.jpg',
'5.jpg', '6.jpg', '7.jpg', '8.jpg']
print(pics)
connect(pics)