4

I need to change an icon color in a png file, where the icon has a transparent background.

I used the following ImageMagick command:

 convert my_icon.png -fill #de2a2a" -colorize 100 output1.png

In Windows, the command colors the icon without the transparent background.

In Linux, it colors "all the icon" including the transparent background.

Why does this happen? How can I solve this problem in Linux?

The ImageMagick version:

  • Windows: ImageMagick 7.0.4-10 Q16 x64
  • Linux: ImageMagick 6.7.8-9 2016-06-16 Q16

The Icon: enter image description here

Thanks

fmw42
  • 46,825
  • 10
  • 62
  • 80
Yosefarr
  • 709
  • 5
  • 12
  • 26

2 Answers2

2

On Ubuntu 18.04 (ImageMagick 6.9.7-4) the issue is no longer reproducible. Also tested on MacOS 10.14 (ImageMagick 7.0.8-47).

Command:

convert ~/Desktop/phone.png -fill "#de2a2a" -colorize 100 ~/Desktop/phone-red.png

enter image description here

Note, you have a typo in your command...

-fill #de2a2a"

Should be: (double-quote before the #)

-fill "#de2a2a"

tresf
  • 7,103
  • 6
  • 40
  • 101
1

I think you have your Windows and Linux versions swapped.

In ImageMagick 6, -colorize only affects the RGB channels and not the alpha. But in ImageMagick 7, -colorize affects all the channels including alpha. So for IM 7, turn alpha off, then colorize, then turn it on again. (Be sure to put quotes on both sides of your hex color)

For IM 7,

enter image description here

magick my_icon.png -alpha deactivate -fill "#de2a2a" -colorize 100 -alpha activate output1.png


enter image description here

Note that deactivate and activate are the IM 7 equivalents of off and on in IM 6

See porting guide

fmw42
  • 46,825
  • 10
  • 62
  • 80