2

I have an icon with a fully transparent background and a semi-transparent, white foreground. I would like to make the foreground fully opaque, can this be achieved with ImageMagick?

I have tried juggling different combinations of these;

http://www.imagemagick.org/discourse-server/viewtopic.php?t=12619

http://www.imagemagick.org/discourse-server/viewtopic.php?t=18196

http://www.imagemagick.org/discourse-server/viewtopic.php?t=16718

, but cannot produce the desired result. Any tips?

EvenLisle
  • 4,052
  • 3
  • 20
  • 40

1 Answers1

4

It would be easier if you posted your icon, but my testing shows that this works for what I think you have:

convert icon.png -channel A -threshold 75% output.png

The above is somewhat coarse as it makes all partially transparent pixels fully opaque. If you wanted to be a bit more surgical, you could only set the opacity to fully opaque when the Red, Green and Blue pixels are greater than 90% and the original opacity (alpha) is between 40%-60% like this:

convert icon.png -channel A \
   -fx "(r>0.9 && g>0.9 && b>0.9 && a>0.4 && a<0.6) ? 1.0 : a" output.png

enter image description here

enter image description here

Mark Setchell
  • 146,975
  • 21
  • 182
  • 306
  • the '-fx' thing is exactly what i needed for applying updated alpha channel only for opaque pixels. thanks a lot! – Denis Jul 18 '18 at 14:02