How to overlay two 39200x30288 images in app

Viewed 40

I want to overlay two 39200x30288 images by Python. I was trying to do that like that:

from PIL import Image

Image.MAX_IMAGE_PIXELS = None

image_1 = Image.open(r"1.png")
image_2 = Image.open(r"2.png")

image_1 = image_1.paste(image_2, (0,0))

print(image_1.size)

And have this type result error code:

Traceback (most recent call last):
  File "e:\Projects\plus\app.py", line 11, in <module>
    print(image_1.size)
AttributeError: 'NoneType' object has no attribute 'size'

Have someone solve this kind of problem?

1 Answers

This line is wrong:

image_1 = image_1.paste(image_2, (0,0))

It doesn't return a new image, because it already knows where to paste image2 - it pastes it onto image1. So it returns None and that is why you get the error message that None has no size.

You simply need:

image_1.paste(image_2, (0,0))
Related