ImageMagick: How to make both black and white transparent?

2.5k Views Asked by At

Converting black and dark shades to transparent works fine with ImageMagick. I even managed to perform a crop and resize in the same line.

convert input.png -background none -fuzz 45% -transparent black -flatten -crop 640x480+12+9 -resize 105% output.png

However, the input image also contains a number of almost white lines, which I also would like to convert to transparent in the output.

How do I go about that? Is it possible to do it within the same command line?

1

There are 1 best solutions below

0
On BEST ANSWER

Sure, just add a second -transparent.

convert -size 512x512 gradient:black-white a.png    # create initial black-to-white gradient

enter image description here

convert -fuzz 20% a.png -transparent black -transparent white result.png  # lose 20% off black end and white end

enter image description here

Or, with extra fuzz...

convert -fuzz 40% a.png -transparent black -transparent white result.png

enter image description here