ImageMagick, replace semi-transparent white with opaque white

大憨熊 提交于 2019-12-11 02:34:47

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/28692694/imagemagick-replace-semi-transparent-white-with-opaque-white

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!