PIL blur the image when I overlay another image

I use the following code to overlay an image on 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 that I use as the background http://i.imgur.com/bwPFT.png , the product is http://i.imgur.com/Ig6qV.jpg , and this is the result shown as http: // i. imgur.com/JfGoS.jpg

Thank any help I can get.

Thanks.

EDIT: Also, when I try background.paste(product, (20,40), product) , I get the error "ValueError: bad mask mask"

+4
source share
2 answers

The problem has nothing to do with PIL. The problem is that the background is .png and you compose it and then output it as .jpg.

.png is lossless, very good for synthetic images like your background ..jpg is loss, very good for natural images like photos. When you render your background as .jpg, it will contain compression artifacts of what you call "spots."

Output the final image as .png. It will be more bytes than .jpg, but it will look better.

+5
source

You open the PNG background image with transparency and save the result as .JPG without transparency. The colors in the transparent area probably remain from the image editor that you used to create the PNG.

+2
source

All Articles