编程语言
首页 > 编程语言> > python实现两张图片拼接

python实现两张图片拼接

作者:互联网

纵向拼接

from PIL import Image


def image_splicing(pic01, pic02):
    with Image.open(pic01) as img_01, \
            Image.open(pic02) as img_02:
        img1_size, img2_size = img_01.size, img_02.size
        base_point = max([img1_size[0], img2_size[0]])
        target = Image.new('RGB', (base_point, img1_size[1] + img2_size[1]), (255, 255, 255))  # 创建背景为白色的空图片
        target.paste(img_01)  # 以坐标(0,0)为基准粘贴第一张图片
        target.paste(img_02, (0, img1_size[1]))  # 以坐标(0,第一张图片的高)为基准粘贴第二张图片
        # target.show()
        save_path = 'D:/image_marge.png'
        target.save(save_path)

        return save_path

标签:target,img,python,Image,两张,拼接,img1,save,size
来源: https://www.cnblogs.com/rong-z/p/16457669.html