1
votes

I have a PNG image with a black shape on transparent background. I need a white shape on a solid black background instead.

How can I achieve that with Imagemagick?

Image example:

I have this:

enter image description here

I want this:

enter image description here

3
Post your image and expected result.zindarod

3 Answers

2
votes

The image you posted is not transparent. It has an opaque checkerboard background. However, if it was transparent, this Imagemagick command should work.

convert image.png -background white -flatten -negate result.png

If using Imagemagick 7, then change convert to magick

1
votes

As @fmw42 said, your image is not a true PNG image. So for your image you can do:

convert input.png -white-threshold 0% -negate out.png

Which will give you:

result

1
votes

Might be able to simply extract the alpha channel to a new image.

For example, let's create a transparent image.

 convert -size 100x100 xc:transparent -fill black -draw 'circle 50,50 50,10' transparent.png

transparent.png

Now we can extract the alpha channel knowing that fully transparent is black, and opaque is white.

 convert transparent.png -alpha extract output.png

output.png