Answer the question
In order to leave comments, you need to log in
How to solve ValueError: bad transparency mask problem in Pillow?
Hi guys, I'm trying to overlay an image on an image, but I get an error: "ValueError: bad transparency mask". Below is the code, please help!!!
img = Image.open('fon.png')
blok = Image.open('ramka1.png')
img.paste(blok, (13, 15), blok)
img.save("gotov.png")
Answer the question
In order to leave comments, you need to log in
Apparently, the mask does not have the correct alpha channel. Perhaps it simply does not exist, although it is expected.
try throwing .convert("RGBA") on the overlay image (aka "mask") like this:
blok = Image.open('ramka1.png').convert("RGBA")
if it doesn't help, then in the first line too add
img = Image.open('fon.png').convert("RGBA")
and at the end you may need
img.save("gotov.png", format="png")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question