Getting the color of a pixel

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

Re: Getting the color of a pixel

Post by snibgo »

We can also use expressions for the coordinates, eg:

Code: Select all

-transparent %[pixel:p{0,h-1}]
"hex:" also works for me. In Windows, "#" isn't a special character so we don't need quotes (but they are harmless). What are the tradeoffs for "hex:" versus "pixel:"? "Hex:" always rounds HDRI values to integers, and clamps values, eg:

Code: Select all

f:\web\im>%IMG7%magick xc:gray(150%) -format %[pixel:p{0,0}] info:
gray(150%)

f:\web\im>%IMG7%magick xc:gray(150%) -format #%[hex:p{0,0}] info:
#FFFFFFFFFFFF
Any other difference between "hex:" and "pixel:"?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting the color of a pixel

Post by fmw42 »

Good point about hex rounding for HDR and also about using h-1.
dholcomb9711
Posts: 16
Joined: 2018-06-08T03:45:59-07:00
Authentication code: 1152

Re: Getting the color of a pixel

Post by dholcomb9711 »

Thanks, guys! You all rock!

It's nice to learn as I move along. I am so much more comfortable using IM than I was 3 months ago because of community help.
Post Reply