Reputation: 78
I'm using Imagemagick in js and I get the color of a pixel with his coordinates like this :
im.identify(['-format', '%[pixel:p{' + values.coordinate + '}]', values.file], function(err, color) {
console.log('color = ', color);
});
It works, but sometimes I get a color like 'grey60' or 'grey40' or something like that. Is there is a way to request that Imagemagick return data in hex or rgb ? Or there is a way to convert this format into hex or rgb ?
Upvotes: 0
Views: 45
Reputation: 53081
In IM 6.9.8-9 and 7.0.5.10, support was added for %[hex:] property similar to %[pixel:], but returning hex values. So this should work in command line mode.
convert xc:red -depth 8 -format "%[hex:u.p{0,0}]\n" info:
FF0000
or adding the # symbol:
convert xc:red -depth 8 -format "\#%[hex:u.p{0,0}]\n" info:
#FF0000
For version of IM before that (at least for unix syntax):
convert xc:red -depth 8 txt: | tail -n +2 | sed -n 's/^.*\(\#.*\) .*$/\1/p'
#FF0000
So if you want a hex color at a coordinate, do something like:
convert rose: -depth 8 -format "\#%[hex:u.p{20,20}]\n" info:
#A93B2A
or
convert rose:[1x1+20+20] txt: | tail -n +2 | sed -n 's/^.*\(\#.*\) .*$/\1/p'
#A93B2A
Upvotes: 1