forked from UnlightedOtaku/doc88Download
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgswitch.py
30 lines (23 loc) · 1.19 KB
/
imgswitch.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
import PIL.Image as Image
import os
IMAGES_PATH = './' # 图片集地址
# ==============
# 记得改这个大小 不然图片会很模糊
IMAGE_SIZE = 960 # 每张小图片的大小
# ==============
IMAGE_ROW = 2 # 图片间隔,也就是合并成一张图后,一共有几行
IMAGE_COLUMN = 2 # 图片间隔,也就是合并成一张图后,一共有几列
IMAGE_SAVE_PATH = './demo.gif' # 图片转换后的地址
# 获取图片集地址下的所有图片名称
image_names = ['1_00.gif','1_01.gif','1_10.gif','1_11.gif']
# 定义图像拼接函数
def image_compose():
to_image = Image.new('RGB', (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE)) # 创建一个新图
# 循环遍历,把每张图片按顺序粘贴到对应位置上
for y in range(1, IMAGE_ROW + 1):
for x in range(1, IMAGE_COLUMN + 1):
from_image = Image.open(IMAGES_PATH + image_names[IMAGE_COLUMN * (y - 1) + x - 1]).resize(
(IMAGE_SIZE, IMAGE_SIZE), Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
return to_image.save(IMAGE_SAVE_PATH) # 保存新图
image_compose() # 调用函数