sharp icon indicating copy to clipboard operation
sharp copied to clipboard

How to produce a composited PNG with an alpha layer but "flattened"

Open jblanche opened this issue 5 years ago • 2 comments

What are you trying to achieve?

I'm wondering if there's a way to manipulate pixels with Sharp so that every pixel with an alpha 0 is replaced with another pixel (keeping the alpha layer). aka going from image to image

But with the same display as the pixels that changed have a 0 alpha.

Have you searched for similar questions?

Yes, but noticed that flatten / remove_alpha completely removes the alpha layer is my understanding is correct.

jblanche avatar Jun 10 '21 10:06 jblanche

Did you see the blend option of the composite operation? I think dest-in (or in, depending on the image order) would be appropriate for this scenario.

https://sharp.pixelplumbing.com/api-composite#composite

lovell avatar Jun 10 '21 11:06 lovell

I hope this information helped. Please feel free to re-open with more details if further assistance is required.

lovell avatar Jul 10 '21 20:07 lovell