Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ValueError: bad transparency mask" when pasting one image onto another with Python Imaging Library?

I'm trying to paste an image onto a backgorund with Python Imaging Library like this:

card = Image.new("RGB", (220, 220), (255, 255, 255))
img = Image.open("/Users/paulvorobyev/test.png")

...

x, y = img.size
card.paste(img, (0, 0, x, y), img)

card.save("test.png")

When I run this code, I get:

 "ValueError: bad transparency mask"

What did I do wrong?

like image 638
plv Avatar asked Jul 07 '15 15:07

plv


1 Answers

Late to the game here, but I just ran into the same issue. After some googling I was able to get my mask to work by making sure all of the images being used were the same mode (specifically "RGBA").

You might try this:

card = Image.new("RGBA", (220, 220), (255, 255, 255)) img = Image.open("/Users/paulvorobyev/test.png").convert("RGBA") x, y = img.size card.paste(img, (0, 0, x, y), img) card.save("test.png", format="png") 
like image 105
Jeremy Avatar answered Sep 21 '22 07:09

Jeremy