A
A
arsfilinov2021-06-17 16:24:24
Python
arsfilinov, 2021-06-17 16:24:24

How to solve ValueError: bad transparency mask problem in Pillow?

60cb4dc202305158211069.png60cb4dcd76ebe203904741.pngHi 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

1 answer(s)
V
Vasily, 2021-06-18
@snaiper04ek

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 question

Ask a Question

731 491 924 answers to any question