'tuple' object has no attribute 'mode'

Viewed 486

Im mostly a beginner in python and cant figure out this error saying that 'tuple' object has no attribute 'mode.

import os
import random
from PIL import Image
from PIL import ImageFilter


Mothmando = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\Mothmando.png")
France = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\France.png")
FranceRGB = France.convert('RGB')
Crimson_Scout = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\Crimson_Scout.png")

Choice = (Mothmando, Crimson_Scout)

Image.Image.paste(Choice, France, box=(1,1,600,450), mask=Choice)
#FranceRGB.paste(Crimson_Scout, France, box=(1,1,600,450), mask=Crimson_Scout)
FranceRGB.save(r"C:\Users\Epicd\Desktop\Fortnite\Pain1.png")

This is the code but the program keeps throwing an error of

Traceback (most recent call last):
  File "C:\Users\Epicd\Desktop\Fortnite\Fortnite.py", line 14, in <module>
    Image.Image.paste(Choice, France, box=(1,1,600,450), mask=Choice)
  File "C:\Python375\lib\site-packages\PIL\Image.py", line 1508, in paste
    if self.mode != im.mode:
AttributeError: 'tuple' object has no attribute 'mode'
[Finished in 0.135s]

How would i fix this error?

1 Answers

It seems that the first input of paste(), or the mask input I don't know, have to be an Image. However you are passing a tuple of Images.

Did you try something like that:

for c in Choice:
    FranceRGB.paste(c, France, box=(1,1,600,450), mask=c)
Related