sharp icon indicating copy to clipboard operation
sharp copied to clipboard

unflatten images to make them transparent still keep white pixels around the edges of the image

Open Nivg opened this issue 2 years ago • 3 comments

I am using the unflatten command to make a version of a given image transparent.

Example for a given image: 300

Here is the result: 300_transparent

As you can see, I still have a residue of white pixels around the resulted image.

I'm not sure why, maybe I'm missing something regarding the understanding of how unflatten works?

Sample code (nothing special here): await sharp(path.join(productPath, fileName + ".png")).unflatten().toFile(path.join(productPath, fileName + "_transparent.png"));

Nivg avatar Feb 12 '24 22:02 Nivg

Did you see https://sharp.pixelplumbing.com/api-operation#unflatten ?

It looks like the "background" of this image consists of white and light grey pixels, with unflatten operating only on the white pixels as documented.

lovell avatar Feb 14 '24 13:02 lovell

Did you see https://sharp.pixelplumbing.com/api-operation#unflatten ?

It looks like the "background" of this image consists of white and light grey pixels, with unflatten operating only on the white pixels as documented.

Yes, I have read the docs. Didn't notice the very light grey pixels, thank you for this insight.

I'll try to use several steps, first to transform the light grey pixels to white and then use the unflatten command.

Thanks!

Nivg avatar Feb 15 '24 14:02 Nivg

@Nivg Were you able to make progress with this?

lovell avatar May 25 '24 14:05 lovell

@Nivg Were you able to make progress with this?

Unfortunately not yet; I am closing this, as the function is doing what it's suppose to do. Thanks!

Nivg avatar May 26 '24 07:05 Nivg