extract colors from one image, other as white

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kissson
Posts: 14
Joined: 2012-05-15T02:15:32-07:00
Authentication code: 13

extract colors from one image, other as white

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: extract colors from one image, other as white

Post 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".
snibgo's IM pages: im.snibgo.com
kissson
Posts: 14
Joined: 2012-05-15T02:15:32-07:00
Authentication code: 13

Re: extract colors from one image, other as white

Post by kissson »

working and great, thanks
Post Reply