【发布时间】:2017-12-26 20:52:01
【问题描述】:
在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。
【问题讨论】:
-
更近一点但没有十六进制数字:
'#%[fx:round(r*256)] %[fx:round(g*256)] %[fx:round(b*256)]\n' -
我觉得你需要做:
declare $(convert rose: -scale 1x1\! -format "rr=%[fx:round(255*r)]\ngg=%[fx:round(255*g)]\nbb=%[fx:round(255*b)]\n" info:)然后做:printf "#%02x%02x%02x\n" $rr $gg $bb
标签: bash imagemagick