Imagemagick 在转义 shell 变量时遇到问题

Imagemagick 在转义 shell 变量时遇到问题

我有一个 imagemagick 命令,它在处理我作为字符串传递的串联 shell 变量时$quote$arcangle遇到了问题。$halfdimension$quote这是文字记录:

$> echo convert grad.png -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc $quote$arcangle -90 $halfdimension$quote +repage -gravity center -crop $dimension"x"$dimension"+0+0" +repage h.png
   convert grad.png -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc '360 -90 450' +repage -gravity center -crop 900x900+0+0 +repage h.png

$> convert grad.png -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc $quote$arcangle -90 $halfdimension$quote +repage -gravity center -crop $dimension"x"$dimension"+0+0" +repage h.png
convert: unable to open image `-90': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to open image `450'': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.

然而,我粘贴了回显命令的输出:

$> convert grad.png -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc '360 -90 450' +repage -gravity center -crop 900x900+0+0 +repage h.png
(h.png is created without problems.)

为什么它在第一个实例中没有被正确解析?

答案1

也许这会起作用,将其写入文件foo.sh

#!/bin/bash
arcangle=270
dimension=768
fin=grad.png
fout=h.png
convert $fin -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc "$arcangle -90" +repage -gravity center -crop "${dimension}x${dimension}+0+0" +repage $fout

./foo.sh

也可以看看这里

相关内容