Image Magick:标题中的%字符未显示

时间:2017-02-26 15:03:35

标签: imagemagick

我正在使用此命令为图像添加标题:

convert -background black -bordercolor black -fill white -size 300x20 -pointsize $myFontsize caption:$title -trim -border 5 -channel A -fx '(lightness/2)+.8' -geometry +$myX+$myY $input +swap -composite $output

但是当$ title包含%字符时,它在标题中不可见,空格字符也不在%后面。

例如,如果$ title ="印度占全球香料产量的75%",标题将为#34;印度贡献全球香料生产的75%"

我该如何避免?

2 个答案:

答案 0 :(得分:0)

这是一个应该可以正常工作的简单示例:

title="India contributes to 75% of the global spice production"
convert -background cyan -pointsize 36 caption:"$title" result.jpg

enter image description here

如果这对您的系统不起作用,您应该检查您是否使用了对变量感到厌倦的shell,然后考虑将 ImageMagick 升级到更新的版本过去4 - 5年。

或者,您可以尝试通过stdin提供字符串,如下所示:

echo "India contributes to 75% of the global spice production" | convert -background cyan -pointsize 36 caption:@- result.jpg

答案 1 :(得分:0)

在Image Magick"标题中:","%"是一个特殊的角色,所以我们可以这样做:

convert -size 300x300 caption:"Width is %w" x.png

因此解决方案是使用另一个%(put double%)来逃避每个%。如果标题是变量$ title:

title=`echo $title | sed s/%/%%/g`