将grey60转换为rgb | ImageMagick的

问题描述:

我使用JS ImageMagick的,我也得到一个像素与他的坐标的颜色是这样的:将grey60转换为rgb | ImageMagick的

im.identify(['-format', '%[pixel:p{' + values.coordinate + '}]', values.file], function(err, color) { 
    console.log('color = ', color); 
}); 

它的工作原理,但有时,我得到了像“grey60”或“grey40”什么颜色像那样。 有没有一种方法可以精确到imagemagick在hexa或rgb中有数据?或者有办法将这种格式转换为hexa或rgb?

+1

某个功能在7.0.5版本左右的某个时间添加到IM中,可让您访问像素的十六进制值。它看起来像这样...“%[hex:u.p {W,H}]”。它不包含输出中的“#”,所以如果你需要的话,你将不得不构建你的字符串来包含它。 – GeeMack

在IM 6.9.8-9和7.0.5.10中,对%[hex:]属性添加了支持,类似于%[pixel:],但返回了十六进制值。所以这应该在命令行模式下工作。

convert xc:red -depth 8 -format "%[hex:u.p{0,0}]\n" info: 
FF0000 

或添加#符号:

convert xc:red -depth 8 -format "\#%[hex:u.p{0,0}]\n" info: 
#FF0000 

对于IM的版本之前(至少对Unix语法):

convert xc:red -depth 8 txt: | tail -n +2 | sed -n 's/^.*\(\#.*\) .*$/\1/p' 
#FF0000 

所以,如果你想在一个十六进制颜色坐标,做类似的事情:

convert rose: -depth 8 -format "\#%[hex:u.p{20,20}]\n" info: 
#A93B2A 

convert rose:[1x1+20+20] txt: | tail -n +2 | sed -n 's/^.*\(\#.*\) .*$/\1/p' 
#A93B2A