python-图片纵向拼接

import os
from PIL import Image
UNIT_SIZE = 220 # the size of image
save_path = '/root/……cyclegan_6.0/web/result3/'
path = "/root/……cyclegan_6.0/web/images"
images = []  # all pic name
def pinjie():

    if not os.path.exists(save_path):
        os.makedirs(save_path)
    for img in os.listdir(path):
        images.append(img)
    for i in range(len(images)/ 6):
        imagefile = []
        j = 0
        for j in range(6):
            imagefile.append(Image.open(path+'/'+images[i*6+j]))
        target = Image.new('RGB', (UNIT_SIZE, UNIT_SIZE*6))  # width, height
        left = 0
        right = UNIT_SIZE
        for image in imagefile:
            target.paste(image, (0, left, UNIT_SIZE, right))
            left += UNIT_SIZE
            right += UNIT_SIZE
            quality_value = 100
        target.save(save_path+'/out_{}.jpg'.format(i), quality=quality_value)
if __name__ == '__main__':
    pinjie()

拼接效果图:


猜你喜欢

转载自blog.csdn.net/lemontree_summer/article/details/80886921
今日推荐