0

I have some code like such:

background = Image.open("background.png").convert("RGBA")
foreground = Image.open("foreground.png").convert("RGBA")
background.paste(foreground, (0, 0), foreground)

For whatever reason, this adds some artifacting that I do not see in Photoshop when stacking the layers:

pillow paste output

See the equivalent region/layer stacked in Photoshop here for comparison:

photoshop layers

Any idea why this is? Should I be loading my png file differently, or saving it with max quality somehow?

  • [this post](https://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil) seems like it has some good suggestions, do any of those work? – Random Davis Jan 25 '22 at 17:09
  • can you post your input images, output images as png's not jpg's. Also why do the pillow and photoshop output have different resolutions? – Hersh Joshi Jan 25 '22 at 17:36
  • I just zoomed in and posted a screenshot of the lines themselves. In any case, thank you for the thread @RandomDavis - This resolved my issue: Image.alpha_composite(background, foreground).save("output.png", format="png") – Not A SWE Jan 25 '22 at 17:53

1 Answers1

0

Issue resolved with:

Image.alpha_composite(background, foreground).save("output.png", format="png")
  • Glad that worked. If you want your question to be more useful for other users searching for a similar issue, you might consider editing your question and adding a more detailed description of the issue - like, "jagged white lines around the border of a transparent part of an image, it looks aliased, and does not appear to have antialiasing or any partial transparency". – Random Davis Jan 25 '22 at 17:57