# 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))
网友评论