How do I get IM to tell me what the color is at pixel x,y?
And, how do I get IM to set -fill (or whatever) to that color without me having to type it in?
Thanks for a great free software.
How to get the color of a pixel?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get the color of a pixel?
unfortunately you need two steps. in unix it would be (to get pixel 0,0)
# create a constant color image
color=`convert image.png -format "%[pixel: u.p{0,0}]" info:`
convert -size 100x100 xc:"$color" swatch.png
or
# replace that color with white
color=`convert image.png -format "%[pixel: u.p{0,0}]" info:`
convert image.png -fill white -opaque "$color" image2.png
see http://www.imagemagick.org/Usage/transform/#fx_escapes
for windows users see http://www.imagemagick.org/Usage/windows/
# create a constant color image
color=`convert image.png -format "%[pixel: u.p{0,0}]" info:`
convert -size 100x100 xc:"$color" swatch.png
or
# replace that color with white
color=`convert image.png -format "%[pixel: u.p{0,0}]" info:`
convert image.png -fill white -opaque "$color" image2.png
see http://www.imagemagick.org/Usage/transform/#fx_escapes
for windows users see http://www.imagemagick.org/Usage/windows/
Re: How to get the color of a pixel?
I see. So in windows it would be:
for /f %%i in ('convert image.png -format "%[pixel: u.p{0,0}]" info:') do set color=%%i
convert image.png -fill white -opaque "%color%" image2.png
Thanks. One more thing. Can you get it to say the color in the "#rrggbb" format?
for /f %%i in ('convert image.png -format "%[pixel: u.p{0,0}]" info:') do set color=%%i
convert image.png -fill white -opaque "%color%" image2.png
Thanks. One more thing. Can you get it to say the color in the "#rrggbb" format?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get the color of a pixel?
In unix, you would do to get pixel 0,0One more thing. Can you get it to say the color in the "#rrggbb" format?
color=`convert image.png[1x1+0+0] -depth 8 txt: | tail -n +2 | sed -n 's/^.*\(#[^ ]*\).*$/\1/p'`
see http://www.imagemagick.org/Usage/files/#txt