【问题标题】:Transform grey60 into rgb | Imagemagick将 gray60 转换为 rgb |图像魔术
【发布时间】:2018-01-25 21:12:14
【问题描述】:

我在 js 中使用 Imagemagick,我得到一个像素的颜色,他的坐标是这样的:

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

它有效,但有时我会得到类似“grey60”或“grey40”之类的颜色。 有没有办法要求 Imagemagick 以 hex 或 rgb 返回数据?或者有办法将这种格式转换成十六进制或rgb?

【问题讨论】:

  • 在 7.0.5 版左右的某个时间向 IM 添加了一项功能,可让您访问像素的十六进制值。它看起来像这样……“%[hex:u.p{W,H}]”。它在输出中不包含“#”,因此如果需要,您必须构建字符串以包含它。

标签: javascript colors hex imagemagick rgb


【解决方案1】:

在 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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    相关资源
    最近更新 更多