首页 > 解决方案 > 潜在的 Imagemagick 线性渐变错误?

问题描述

我正在尝试在 Imagemagick 中构建一个带有渐变的矩形。当我用纯色填充运行我的脚本时,我得到了构建矩形的预期行为,但是当我使用渐变作为 -fill 时,我得到一个奇怪的渐变行为,它们似乎在形状中间重新开始它们是被卷入。任何人都可以推荐一个修复或解决这个问题吗?在下面的示例中,我仅将渐变应用于底部展开作为示例(查看黑色、黑色/白色比较)。在第一幅图像中,它按预期填充为黑色,但在第二幅图像中,渐变“行为不端”并在传播的中间重新开始,没有明显的原因。

谢谢。

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

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

在此处输入图像描述

标签: imagemagickimagemagick-convert

解决方案


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

转换 -size 240x702 -填充渐变:'#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


在此处输入图像描述


推荐阅读