在 Windows 上使用 ImageMagick 并排附加两个 gif

append two gifs side-by-side with ImageMagick on Windows

在 Linux (Ubuntu) 上,我能够使用此命令附加两个动画 gif(相同大小,相同帧数):

convert file1.gif'[0]' -coalesce \( file2.gif'[0]' -coalesce \) \
          +append -channel A -evaluate set 0 +channel \
          file1.gif -coalesce -delete 0 \
          null: \( file2.gif -coalesce \) \
          -gravity East -layers Composite output.gif

您还可以在此处找到此命令:Animation Modifications

在 Windows 上,此命令不起作用。它产生错误:

convert torusEnlargingSpheres3.gif'[0]' -coalesce \( torusEnlargingSpheres6.gif'[0]' -coalesce \) +append -channel A -evaluate set 0 +channel torusEnlargingSpheres3.gif -coalesce -delete 0 null:: \( torusEnlargingSpheres6.gif -coalesce \) -gravity East -layers Composite output.gif

convert.exe: UnableToOpenBlob `torusEnlargingSpheres3.gif'[0]'': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `GIF'[0]'' @ error/constitute.c/ReadImage/504.
convert.exe: UnableToOpenBlob `\(': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/504.
convert.exe: UnableToOpenBlob `torusEnlargingSpheres6.gif'[0']': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `GIF'[0']' @ error/constitute.c/ReadImage/504.
convert.exe: UnableToOpenBlob `\)': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/504.
convert.exe: UnableToOpenBlob `\(': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/504.
convert.exe: UnableToOpenBlob `\)': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/504.

我应该更改什么才能在 Windows 上使用此命令?

此命令不会产生错误,但不会附加图像:

convert file1.gif"[0]" -coalesce ^( file2.gif"[0]" -coalesce ^) +append -channel A -evaluate set 0 +channel file1.gif -coalesce -delete 0 null:: ^( file2.gif -coalesce ^) -gravity East -layers Composite output.gif

Windows 上的引用与 Unix 不同。以下是有关如何将 Linux 引用转换为 Window 引用的一些想法。请注意,大多数在线 ImageMagick 示例都使用 Linux 样式引用,因此这与任何 Windows 用户特别相关。


1.行继续

在 Linux 上,反斜杠用作换行符,但 Windows 使用插入符号 (^),所以这个 (Linux):

convert image.png image.png \
   +append result.png

变成这个 (Windows):

convert image.png image.png ^
    +append result.png

2。用双引号替换单引号

在Linux上参数可以用单引号引起来,但是在Windows上需要双引号,所以这个(Linux):

convert 'image with spaces.png' info:

变成这个 (Windows):

convert "image with spaces.png" info:

3。转到 Windows

时,某些字符需要转义删除

在 Linux 上,有些字符需要在前面加上反斜杠来转义,例如 ()!,但在 [=90= 上不需要这样做], 所以这个 (Linux):

convert image.png \( image.png -negate \) +append result.png

变成这个 (Windows):

convert image.png ( image.png -negate ) +append result.png

4.双百分号

从 Linux 到 Windows 时将百分号加倍,所以这个 (Linux):

convert xc:"gray(128)" -depth 8 -threshold 51% txt:

变成这个 (Windows):

convert xc:"gray(128)" -depth 8 -threshold 51%% txt:

5.去Windows

时有些字符需要转义

有些字符需要在移动到 Windows 之前添加插入符号以转义它们,例如 |&>< , 所以这个 (Linux):

convert image.png -resize 1024x768\> result.png

变成这个 (Windows):

convert image.png -resize 1024x768^> result.png

6.注意评论

井号 (#) 在 Linux 中引入了注释,这些可能最好删除并放在其他地方,所以这个 (Linux):

convert input.png -auto-level result.png    # comment

可能成为其中之一 (Windows):

convert input.png -auto-level result.png
convert input.png -auto-level result.png    :: comment  

如果您知道任何其他情况,或者我的任何情况不正确,或者可以更好地解释,请通过评论告诉我,我会尽量保持列表的正确性,以供其他人参考.

我仍然不知道如何修复该命令。让我为 Windows 提供

这里是:

1) 文件 a-0001.gif, ...:

file1.gif 的单独帧
convert file1.gif -coalesce a-%04d.gif  

2) 文件 aa-0001.gif, ...:

file2.gif 的单独帧
convert file2.gif -coalesce aa-%04d.gif 

3) 附加帧 side-by-side(使用 %~nxf 获取相对路径 - 重要):

for /r %f in (a-*.gif) do convert %f a%~nxf +append %f

4) 加入附加帧:

convert -loop 0 -delay 20 a-*.gif result.gif

我可能会用这样的东西模拟“+append”...

读入 file1 GIF,合并并设置其页面几何形状以将其宽度向右扩展一倍。再次合并以创建额外的 canvas 区域。

然后包含 "null:" 以将 file1 帧与 file2 帧分开。

然后读入file2 GIF并合并它。

通过将重力设置为东并使用“-layers composite”将每个 file2 帧合成在其伙伴 file1 帧的扩展区域上来完成。设置延迟和“-loop 0”,并命名输出文件。

执行此操作的命令看起来像这样...

convert ( file1.gif -coalesce -set page %[fx:w*2]x%[h]+0+0 -coalesce ) ^
   null: ( file2.gif -coalesce ) -gravity east -layers composite ^
   -set delay 20 -loop 0 result.gif

要在 BAT 脚本中使用这样的命令,请将单个百分号“%”变为双百分号“%%”。