ImageMagick如何输出十六进制颜色而不是SRGB?

问题描述 投票:2回答:2

this question,有人问如何以十六进制表示法获得图像的平均颜色。经过一些研究,我找到了一个使用ImageMagick的有点工作的解决方案:

user@laptop:~$ convert rose: -scale 1x1\! -format '%[pixel:s]\n' info:-

问题是,这打印srgb(146,89,80)而不是所需的#925950

我试着阅读-format的文档,它确实提到了%[hex:]“的东西”,但是当用%[pixel:s]代替%[hex:s]时,我收到以下错误:

convert: unknown image property "%[hex:s]" @ warning/property.c/InterpretImageProperties/3678.

我也试过阅读FX Expressions的文档,但我不知道如何将结果输出为十六进制代码而不是SRGB。

bash imagemagick
2个回答
2
投票

您最有可能出现错误,因为您的ImageMagick版本太旧了。更改日志说:

2017-06-02 6.9.8-9 Cristy <quetzlzacatenango@image...>
Add support for 'hex:' property.

如果该版本或以后使用:

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版本和平台,因为语法可能会有所不同,可能会添加新功能或修复错误。


2
投票

附加:

| awk -F '[(,)]' '{printf("#%x%x%x\n",$2,$3,$4)}'

输出:

#925950
© www.soinside.com 2019 - 2024. All rights reserved.