I’m using the following code to overlay an image onto another image using PIL
path = "/home/blah.png"
background = Image.open(path)
product = Image.open("/home/51tmBaivYhL._SL75_.jpg")
background.paste(product, (20,40))
background.save("/home/newImage.jpg")
These are the images I’m using as the background https://i.stack.imgur.com/wuJu1.png , product https://i.stack.imgur.com/Vg0Vh.jpg and this is what the result is showing up as https://i.stack.imgur.com/A2Rzu.jpg
Would appreciate any help I can get.
Thanks.
EDIT: Also, when I try background.paste(product, (20,40), product), I get the error “ValueError: bad transparency mask”
The problem has nothing to do with PIL. The problem is the background is a .png, and you are composing it, and then outputting it as a .jpg.
.png is lossless, very good for synthetic images like your background. .jpg is lossy, very good for natural images like photographs. When you output your background as .jpg, it will contain compression artifacts, what you call “smudges”.
Output your final image as a .png. It will be more bytes than a .jpg, but will look better.