Why does PIL fail to merge 2 images in my code?

后端 未结 1 1834
南方客
南方客 2021-01-16 23:59

I am trying to combine 2 images into a larger one with Image.paste function. I start by creating an image that can hold both images, and then paste in the 2 images:

相关标签:
1条回答
  • 2021-01-17 00:41

    There are two possible issues.

    1. Are you sure your 4-tuple (0, height, width, textHeight) is correct? It should be (left, upper, right, lower) pixel coordinates. In this case the pasted image must match the size of the region, and I think this is where your error lies. Alternatively you can give a 2-tuple giving just the upper left corner of where you want to paste the picture. See: http://effbot.org/imagingbook/image.htm

    2. Are you sure that height, width, textHeight are ints and not floats?

    You could try something like this:

    x, y = img1.size
    wrapper.paste(textImage,(0,height,x,y))
    
    0 讨论(0)
提交回复
热议问题