how to get the color value of a point?

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
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

how to get the color value of a point?

Post by linjuming »

Image

which is similar with color picker.
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get the color value of a point?

Post by linjuming »

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get the color value of a point?

Post by fmw42 »

looks like a bug in Imagick.

try this in the PHP exec() command to get 8-bit RGB values.

convert im_logo_examples.gif[1x1+140+160] -format "%[fx:floor(255*u.r)],%[fx:floor(255*u.g)],%[fx:floor(255*u.b)]" info:
2,90,164
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to get the color value of a point?

Post by anthony »

See IM examples, Quantization and Dithering, extracting image colors
http://www.imagemagick.org/Usage/quantize/#extract

It first talks about all the colors, but then goes to methods for getting the color of a specify pixel.

The best way from command line is to either use a -format FX/Pixel escape to get a specific pixel values, or to crop the image down to just that one pixel and then use format or txt: output.

Code: Select all

convert rose: -format '%[pixel:p{40,30}]' info:-
rgb(232,54,58)

Code: Select all

convert rose: -crop 1x1+40+30 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (232, 54, 58) #E8363A rgb(232,54,58)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to get the color value of a point?

Post by fmw42 »

The trouble with [pixel: ...] is that sometimes it returns a color name and not an rgb triplet. That was why I used [fx: ...] in my example.
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to get the color value of a point?

Post by linjuming »

thank you , very good answer.
Post Reply