图片拼接

# coding:utf-8
# !/usr/bin/env python
import os
from PIL import Image

imageWidth = 600
imageHeight = 420
rows = 2
cols = 3

target = Image.new("RGB",size=(imageWidth*cols,imageHeight*rows))

for root,dirs,files in os.walk(r"C:\Users\sin\Desktop\pics"):
    sorted_filelists = sorted(files,reverse=False)
    length = len(sorted_filelists)
    for i in range(int(length / 3)):
        left_y = imageHeight*i
        right_y = left_y + imageHeight
        for j in range(3):
            left_x = imageWidth*j
            right_x = left_x + imageWidth
            img = Image.open(os.path.join(root,sorted_filelists[i*3+j]))
            img.thumbnail((imageWidth,imageHeight))
            target.paste(img,(left_x,left_y,right_x,right_y))
    target.save(os.path.join(root,"test.jpg"),"jpeg",quality=100,dpi=(10.0,10.0))
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容