Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a white background - sharp library

Tags:

node.js

sharp

Is it possible to replace a white background of an image with transparency using the sharp library?

like image 531
Brian F Avatar asked Sep 15 '26 22:09

Brian F


1 Answers

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");
like image 58
GoldenAxe Avatar answered Sep 17 '26 15:09

GoldenAxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!