Stitching Photos together

前端 未结 5 672
长情又很酷
长情又很酷 2020-12-05 03:31

So for this project I\'m working on, I have 2 photos. These two photos need to be stitched together, one on the top and one on the bottom, and then you will be able to see t

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 04:00

    I did vertical stitching like this - it is same code from @d3ming

    07: def merge_images(file1, file2):
    08:     """Merge two images into one vertical image
    09:     :param file1: path to first image file
    10:     :param file2: path to second image file
    11:     :return: the merged Image object
    12:     """
    13:     image1 = Image.open(file1)
    14:     image2 = Image.open(file2)
    15: 
    16:     (width1, height1) = image1.size
    17:     (width2, height2) = image2.size
    18: 
    19:     # result_width = width1 + width2
    20:     result_width = width1
    21:     # result_height = max(height1, height2)
    22:     result_height = height1 + height2
    23: 
    24:     print (height2)
    25: 
    26:     result = Image.new('RGB', (result_width, result_height))
    27:     result.paste(im=image1, box=(0, 0))
    28:     result.paste(im=image2, box=(0, height1))
    29:     return result
    

    line 19-22 - only height will change for stitching

    paste the second image on line-28 box=(width1, 0) changes to box=(0, height1)

提交回复
热议问题