Page 1 of 1

extract colors from one image, other as white

Posted: 2014-06-12T23:44:50-07:00
by kissson
now what I am doing,

rem extract #00FF00, other as white
convert input.png -fill white +opaque "#00FF00" temp1.png
rem extract #FFFFD5, other as white
convert input.png -fill white +opaque "#FFFFD5" temp2.png
rem make it transparent
convert temp1.png -transparent white temp1_transp.png
convert temp2.png -transparent white temp2_transp.png
rem make 2 transparent png together
composite temp1_transp.png temp2_transp.png temp3.png
rem make the transparent white
convert temp3.png -background white -flatten result.png

can it do it in a single command ? because I need tens of colors and my code is not quite scalable, and skip the creation of temp image.
thanks.

Re: extract colors from one image, other as white

Posted: 2014-06-13T03:14:28-07:00
by snibgo
What is your platform? From "rem", perhaps it is Windows BAT. If not, you will need to adjust this. Untested.

Code: Select all

convert ^
  input.png ^
  ( -clone 0 ^
    -fill white +opaque "#FFFFD5" ^
    -transparent white ^
  ) ^
  ( -clone 0 ^
    -fill white +opaque "#00FF00" ^
    -transparent white ^
  ) ^
  -delete 0 ^
  -composite ^
  -background white -flatten ^
  result.png
I think that "-fill white +opaque "#FFFFD5" -transparent white" can be simplified to "+transparent #FFFFD5".

Re: extract colors from one image, other as white

Posted: 2014-06-13T04:23:30-07:00
by kissson
working and great, thanks