ImageMagick如何输出十六进制颜色而不是SRGB? [英] How can ImageMagick output hex colours instead of SRGB?
问题描述
在这个问题,有人问如何以十六进制表示法获取图像的平均颜色。经过一些研究,我找到了一个使用ImageMagick的有点工作的解决方案:
In this question, someone asked how to get the average colour of an image in hexadecimal notation. After some research, I found a somewhat working solution using ImageMagick:
user@laptop:~$ convert rose: -scale 1x1\! -format '%[pixel:s]\n' info:-
问题是这个打印 srgb(146,89,80)
而不是所需的#925950
。
The problem is that this prints srgb(146,89,80)
instead of the desired #925950
.
我试过阅读 -format的文档
,确实提到了%[hex:]
thing,但在替换%[pixel]时:s]
对于%[hex:s]
,我收到以下错误:
I tried reading through the documentation of -format
, which did mention a %[hex:]
"thing", but when substituting %[pixel:s]
for %[hex:s]
, I get the following error:
convert: unknown image property "%[hex:s]" @ warning/property.c/InterpretImageProperties/3678.
我也尝试阅读 FX Expressions
,但我不知道如何将结果输出为十六进制代码而不是SRGB。
I also tried reading the documentation for FX Expressions
, but I have no idea how I would go about outputting the result as hex code instead of SRGB.
推荐答案
您最有可能出现错误,因为您的ImageMagick版本太旧了。更改日志说:
You got an error most likely because your version of ImageMagick is too old. The changelog says:
2017-06-02 6.9.8-9 Cristy <quetzlzacatenango@image...>
Add support for 'hex:' property.
如果该版本或更高版本使用:
If that version or later use:
convert rose: -scale 1x1\! -format "%[hex:u]\n" info:
925950
convert rose: -scale 1x1\! -format "%[hex:s]\n" info:
925950
convert rose: -scale 1x1\! -format "%[hex:u.p{0,0}]\n" info:
925950
convert rose: -scale 1x1\! -format "#%[hex:u]\n" info:
#925950
convert rose: -scale 1x1\! -format "#%[hex:s]\n" info:
#925950
convert rose: -scale 1x1\! -format "#%[hex:u.p{0,0}]\n" info:
#925950
如果更早,那么
convert rose: -scale 1x1\! txt: | tail -n +2 | sed -n 's/^.*[#]\(.*\) .*$/\1/p'
925950
convert rose: -scale 1x1\! txt: | tail -n +2 | sed -n 's/^.*\([#].*\) .*$/\1/p'
#925950
在询问有关ImageMagick命令的问题时,最好提供ImageMagick版本和平台,因为语法可能会有所不同,可能会添加新功能或修复错误。
It is always best to provide your ImageMagick version and platform, when asking questions about ImageMagick commands, since syntax may vary and new feature may be added or bugs fixed.
这篇关于ImageMagick如何输出十六进制颜色而不是SRGB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!