Hacktisch
Hacktisch

Reputation: 1514

GraphicksMagic: white -> transparent

I found many forum posts about this but none of what I found could solve it for me:

I need to convert the white background of images like the one attached to transparent using GraphicsMagick (or ImageMagick). But when I run any of the below commands, the background becomes black instead of transparent.

In GraphicsMagick I tried:

gm convert input.png -opaque white output.png
gm convert input.png -fill transparent -opaque white output.png
gm convert input.png -background transparent -opaque white output.png
gm convert input.png -background transparent -fill transparent -opaque white output.png

enter image description here

My application is in nodeJS so a nodeJS solution using the GM package would be even better;

gm('input.png')
    .dosomething()
    .write('output.png');

Upvotes: 0

Views: 1577

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207355

This should do it even more simply:

gm convert wave.png -transparent white result.png

Upvotes: 3

JCOidl
JCOidl

Reputation: 464

The image does not already have an alpha channel, so use -matte:

gm convert input.png -matte -fill transparent -opaque white output.png

Upvotes: 2

Related Questions