python图片云

Python 小工具 把图片拼接成任意大小新图片 代码比较简单 看注释就好

# -*- coding:utf-8 -*-
#图片拼接
import PIL.Image as Image
import os, sys
file_dir = "C:\\Users\Administrator\Desktop\zhihu\zhihu_user\images\\full"
def g():
    for root, dirs, files in os.walk(file_dir):
        for file in files:
            yield os.path.join(root,file)
gfile=g()
import os
from PIL import Image
'''
把当前目录下的10*10张jpeg格式图片拼接成一张大图片
'''
:# 图片压缩后的大小
width_i = 100
height_i = 100
:# 每行每列显示图片数量
line_max = 10
row_max = 10
:# 参数初始化
all_path = []
num = 0
pic_max = line_max * row_max
dirName = os.getcwd()
toImage = Image.new('RGBA', (width_i * line_max, height_i * row_max))
for i in range(0, row_max):
    for j in range(0, line_max):
        pic_fole_head = Image.open(next(gfile))
        width, height = pic_fole_head.size
        tmppic = pic_fole_head.resize((width_i, height_i))
        loc = (int(i % line_max * width_i), int(j % line_max * height_i))
        # print("第" + str(num) + "存放位置" + str(loc))
        toImage.paste(tmppic, loc)
        num = num + 1
print(toImage.size)
toImage.save("C:\\Users\Administrator\Desktop\merged.png")

git https://github.com/tongchengbin/pythontools/blob/master/imgCloud.py

posted @ 2018-02-02 14:02  童小哥总是不开心。  阅读(498)  评论(0编辑  收藏  举报