Is it possible to replace a white background of an image with transparency using the sharp library?
You can use the unflatten command assuming you meet the following requirements:
Ensure the image has an alpha channel with all white pixel values made fully transparent. Existing alpha channel values for non-white pixels remain unchanged. This feature is experimental and the API may change.
sharp docs related to unflatten
for example:
await sharp("my_image.png").unflatten().toFile("my_image_transparent.png");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With