复制像素颜色 (ImageMagick)

发布于 2025-01-11 10:57:13 字数 336 浏览 2 评论 0原文

如何指定给定像素的颜色来填充?

convert -gravity center -background rgb\(222,97,56\) -fill "#%[hex:u.p{10,10}/2]" -size 120x60 -pointsize 42 label:Test -depth 8 out.png

错误:转换:无法打开图像“#%[hex:up{10,10}/2]”:没有此类文件或目录

-format '%[hex:p{10,10}/2]\n' info:

返回“6F311C”,但 -fill“#6F311C”可以工作。

How can I specify a color from an given pixel to -fill ?

convert -gravity center -background rgb\(222,97,56\) -fill "#%[hex:u.p{10,10}/2]" -size 120x60 -pointsize 42 label:Test -depth 8 out.png

Error : convert: unable to open image '#%[hex:u.p{10,10}/2]': No such file or directory

-format '%[hex:p{10,10}/2]\n' info:

returns "6F311C" and -fill "#6F311C" works though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

作妖 2025-01-18 10:57:13

更新的答案

如果您想使用label:而不是-annotate,请尝试此操作:

magick -gravity center -size 100x100 xc:yellow  \
   -fill black -draw "rectangle 10,10 100,100" \
   -fill '%[pixel:p{0,0}]' -background magenta -size 100x80 -pointsize 42 label:"Label" -append result.png

在此处输入图像描述

原始答案

我想你想要这个:

magick -gravity center -size 100x100 xc:yellow  \
    -fill black -draw "rectangle 10,10 100,100" \
    -fill '%[pixel:p{0,0}]' -annotate 0 "text" result.png

在此处输入图像描述

前 2 行创建一个黄色画布,其中黑色矩形覆盖右下部分,左上角像素为黄色。然后从像素 (0,0) 获取填充颜色并用于文本注释。

Updated Answer

Try this if you want to use label: rather than -annotate:

magick -gravity center -size 100x100 xc:yellow  \
   -fill black -draw "rectangle 10,10 100,100" \
   -fill '%[pixel:p{0,0}]' -background magenta -size 100x80 -pointsize 42 label:"Label" -append result.png

enter image description here

Original Answer

I think you want this:

magick -gravity center -size 100x100 xc:yellow  \
    -fill black -draw "rectangle 10,10 100,100" \
    -fill '%[pixel:p{0,0}]' -annotate 0 "text" result.png

enter image description here

The first 2 lines create a yellow canvas with a black rectangle overlaying the bottom-right part leaving the top-left pixel yellow. The fill colour is then taken from pixel (0,0) and used for the text annotation.

肤浅与狂妄 2025-01-18 10:57:13

以下内容适用于 Imagemagick 7。将 # 符号添加到十六进制命令中。

magick -size 120x60 -background "rgb(222,97,56)" -depth 8 -fill "#%[hex:u.p{10,10}/2]" -pointsize 42 -gravity center label:Test -depth 8 out.png

输入图片此处描述

请注意,Imagemagick 7 的实现是为了添加 Imagemagick 6 中不可用的此类内联计算。

The following works for me in Imagemagick 7. Add the # sign to your hex command.

magick -size 120x60 -background "rgb(222,97,56)" -depth 8 -fill "#%[hex:u.p{10,10}/2]" -pointsize 42 -gravity center label:Test -depth 8 out.png

enter image description here

Note that Imagemagick 7 was implemented to add such in-line computations that were not available in Imagemagick 6.

鯉魚旗 2025-01-18 10:57:13

为了避免 Imagemagick 中不同操作系统平台出现问题,您应该使用双引号。

以下内容应返回蓝色的十六进制值:

magick xc:red xc:blue xc:green1 +append -depth 8 -format "%[hex:u.p{1,0}]" info:

0000FFF

如果您确实想要进行除法,那么

magick xc:red xc:blue xc:green1 +append -depth 8 -format "%[hex:u.p{1,0}/2]" info:

000080

将其放入标签中,

# create image
magick xc:red xc:blue xc:green1 +append rgb.png

# put color into label
magick rgb.png -set label "%[hex:u.p{1,0}/2]" rgb.png

# check label
magick rgb.png -format "%l" info:

000080

To avoid issue in different OS platforms in Imagemagick, you should use double quotes.

The following should return the hex value for blue:

magick xc:red xc:blue xc:green1 +append -depth 8 -format "%[hex:u.p{1,0}]" info:

0000FFF

If you really want to do division, then

magick xc:red xc:blue xc:green1 +append -depth 8 -format "%[hex:u.p{1,0}/2]" info:

000080

So to put that into a label,

# create image
magick xc:red xc:blue xc:green1 +append rgb.png

# put color into label
magick rgb.png -set label "%[hex:u.p{1,0}/2]" rgb.png

# check label
magick rgb.png -format "%l" info:

000080
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文