命令行中的 Imagemagick 命令和 windows powershell

Imagemagick command in command line and windows powershell

我正在尝试 运行 我的 windows powershell 中的 imagemagick 命令行,但它不起作用,如果我 运行 它在我的常规命令行中它确实有效。

命令如下所示:

(我不需要换行符,只是为了让命令更易读)

convert -bordercolor none -background none -gravity center ^
k1.jpg -border 5x5 ^
( k2.jpg k3.jpg k4.jpg -border 5x5 +append ) ^
( k5.jpg k6.jpg k1.jpg -border 5x5 +append ) ^
-append -border 5x5 -resize 720x480 output.png

如果我在我的 powershell 中 运行 它会出现以下错误:(我必须将其翻译成英文)

k2.jpg : the wording "k2.jpg" was not detected as a name of a cmdlet, a function, a script file.

编辑:

其实我不需要换行符,我只是把它们放起来让代码更易读,如果你有没有换行符的建议也很好。

编辑:

我试过马特的建议是这样的:

convert --% -bordercolor none -background none -gravity center k1.jpg -border 5x5 (k2.jpg k3.jpg k4.jpg -border 5x5 +append) (k5.jpg k6.jpg k7.jpg -border 5x5 +append) -append -border 5x5 -resize 720x480 output.png

我得到了关注 error/message:

convert.exe: unable to open image '(k2.jpg': No such file or directory @ error/blob.c/OpenBlob/2695. convert.exe: unrecognized option `+append)' @ error/convert.c/ConvertImageCommand/764.

主要问题是 PowerShell 正试图像处理 PowerShell 语法那样对待那些。 () 表示一个表达式。

There are multiple ways of handling exe's in PowerShell。根据您的意图和 PowerShell 版本,某些选项比其他选项更痛苦(有些甚至被更喜欢的方法弃用)。

最简单的方法就是使用停止解析运算符:

The stop-parsing symbol (--%), introduced in Windows PowerShell 3.0, directs Windows PowerShell to refrain from interpreting input as Windows PowerShell commands or expressions.

所以你可以这样做:

convert --% -bordercolor none -background none -gravity center....

我没有测试您在做什么的环境,但也许您可以在这些参数周围使用引号,这样 PowerShell 就不会将其视为字符串。

"( k2.jpg k3.jpg k4.jpg -border 5x5 +append )"