EADST

Python: Merge Two Images

Python: Merge Two Images

from PIL import Image

def get_concat_h(im1, im2):
    dst = Image.new('RGB', (im1.width + im2.width, im1.height))
    dst.paste(im1, (0, 0))
    dst.paste(im2, (im1.width, 0))
    return dst

def get_concat_v(im1, im2):
    dst = Image.new('RGB', (im1.width, im1.height + im2.height))
    dst.paste(im1, (0, 0))
    dst.paste(im2, (0, im1.height))
    return dst

save_dir = "./merge"
for root, _, imgs in os.walk("./left_imgs/"):
        for img in imgs:
            im1 = Image.open('./left_imgs/{}'.format(img))
            im2 = Image.open('./right_imgs/{}'.format(img))
            new = get_concat_h(im1, im2)
            new.save(os.path.join(save_dir, img))
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
站点统计

本站现有博文266篇,共被浏览440722

本站已经建立2019天!

热门文章
文章归档
回到顶部