Bash变量中的Imagemagick参数不能正确解释?

时间:2016-12-16 13:53:54

标签: bash command-line-interface quoting

我需要使用Imagemagick以画布为基础以及其他一些图像来构图。

目前,最简单的方案正常运行(请注意,您需要两个名为src1.pngsrc2.png的图片才能实现此目的:

convert src1.png -gravity northwest -draw 'image Over 10,10 0,0 "src2.png"' result.png

但是,我需要动态伪造这些参数,以便能够在src1.png之上绘制一个,两个或更多图像。

为此,我尝试将参数存储在变量中,然后进行替换。我尝试了两个版本,包括数组和简单的字符串:

DRAWOPTS=(-draw 'image Over 10,10 0,0 \"src2.png\"')
convert src1.png -gravity northwest ${DRAWOPTS[@]} result.png

DRAWOPTS="-draw 'image Over 10,10 0,0 \"src2.png\"'"
convert src1.png -gravity northwest $DRAWOPTS result.png

但我总是遇到这些错误:

convert.im6: non-conforming drawing primitive definition `image' @ error/draw.c/DrawImage/3160.
convert.im6: unable to open image `Over': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `Over' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `10,10': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `10,10' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `0,0': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `0,0' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `"src2.png"'': No such file or directory @ error/blob.c/OpenBlob/2641.
convert.im6: no decode delegate for this image format `"src2.png"'' @ error/constitute.c/ReadImage/544.
convert.im6: non-conforming drawing primitive definition `image' @ error/draw.c/DrawImage/3160.

我无法让它发挥作用。请在这个引用地狱需要一些帮助。

1 个答案:

答案 0 :(得分:1)

你需要引用数组的扩展。

DRAWOPTS=( -draw 'image Over 10,10 0,0 "src2.png"' )
convert src1.png -gravity northwest "${DRAWOPTS[@]}" result.png