潜在的 Imagemagick 线性渐变错误?

Potential Imagemagick linear-gradient bug?

我正在尝试在 Imagemagick 中构建一个带有渐变的矩形。当我 运行 我的脚本使用纯色填充时,我得到了构建矩形的预期行为,但是当我为 -fill 使用渐变时,我得到了一种奇怪的渐变行为,它们似乎在中间重新开始他们被吸引到的形状。任何人都可以为此推荐修复或解决方法吗?在下面的示例中,我仅将渐变应用于底部展开作为示例(查看黑色,black/white 比较)。在第一张图片中,它按预期填充为黑色,但在第二张图片中,渐变 'misbehaves' 并在传播的中间重新开始,原因不明。

谢谢。

带有结果的工作命令示例:

convert -size 240x702 -fill black -draw "rectangle 40,2500 280,1798"  legend.png legend.png    

带有结果的损坏命令示例:

convert -size 240x702 -fill gradient:'#FFFFFF'-'#000000' -draw "rectangle 40,2500 280,1798"  legend.png legend.png

抱歉,您的 ImageMagick 命令行语法在几个方面存在错误:

convert -size 240x702 -fill gradient:'#FFFFFF'-'#000000' -draw "rectangle 40,2500 280,1798" legend.png legend.png


First, you have your input legend.png image after your draw, so there is nothing to draw on. You need to read your input right after convert. See https://imagemagick.org/Usage/basics/#syntax

Second do not put quotes about each color in the gradient. Just put it around both.

Third, your -size argument is smaller than the size of the rectangle (and in fact is not used for anything). So you are trying to draw with a larger area than the image you are drawing on.

Fourth, there is no -fill for a gradient in Magick Vector Graphics as listed at https://imagemagick.org/script/magick-vector-graphics.php

Fifth, your command has no color involved in the gradient, but you show a gradated color image. Where is the color coming from or where is the grayscale gradient being used?


我没有您输入的 legend.png 图片。但是您想要做的是创建一个渐变图像,然后将其合成到正确位置的图例背景上。由于我没有你的图例,我将使用你的输出作为图例。

convert legend.png \( -size 240x2340 gradient:'#FFFFFF-#000000' \) -geometry +40+160 -compose over -composite result.png