【问题标题】:append two gifs side-by-side with ImageMagick on Windows在 Windows 上使用 ImageMagick 并排附加两个 gif
【发布时间】:2018-03-26 09:55:11
【问题描述】:

在 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

【问题讨论】:

  • 我认为您需要用插入符号 (^) 替换作为行继续字符的双斜杠。并在打开和关闭括号之前删除双反斜杠。并将单引号替换为双引号。
  • @MarkSetchell 谢谢。我试过了,不成功。
  • 请编辑您的问题以显示您的尝试,谢谢。另请查看此答案的底部...stackoverflow.com/a/49358428/2836621
  • @MarkSetchell 我刚刚编辑过。感谢您的链接。
  • 我认为括号前不需要插入符号。抱歉,我的 Windows 知识有限。

标签: windows imagemagick


【解决方案1】:

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

这里是:

1) file1.gif 在文件a-0001.gif, ... 中的单独帧:

convert file1.gif -coalesce a-%04d.gif  

2) file2.gif 在文件aa-0001.gif, ... 中的单独帧:

convert file2.gif -coalesce aa-%04d.gif 

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

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

4) 加入附加帧:

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

【讨论】:

    【解决方案2】:

    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 上,某些字符需要通过在它们前面加上反斜杠来转义,例如 (、)、!,但在 Windows 上这是不必要的,因此(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.当心cmets

    井号 (#) 在 Linux 中引入了 cmets,这些可能最好将其移除并放在其他地方,所以这个 (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  
    

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

    【讨论】:

      【解决方案3】:

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

      读入文件 1 GIF,合并,并设置其页面几何图形以将其向右扩展为两倍宽度。再次合并以创建额外的画布区域。

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

      然后读入file2 GIF并合并它。

      最后将重力设置为东,并使用“-layers composition”将每个 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 脚本中使用这样的命令,请将单个百分号“%”转换为双倍“%%”。

      【讨论】:

      • 我们要改变什么才能垂直追加? 0+0%[fx:w*2]x%[h] 和 gravity south?
      • 不...我没有找到如何垂直追加。有什么想法吗?
      • 您可以设置页面几何形状,使用“-set page %[h]x%[fx:h*2]+0+0 -”将“file1.gif”框架的高度加倍 -合并”。然后使用“-gravity south”和“-layers composite”应该在扩展的下部区域“file1.gif”帧上合成“file2.gif”帧。结果就像是垂直的“-append”。
      • 谢谢。有用。但不是 %[w]x%[fx:h*2]+0+0 而不是 %[h]x%[fx:h*2]+0+0 吗? (在我的情况下 width=height 所以没有区别)。
      • 是的。我的错。在 FX 表达式中,“w”是宽度,“h”是高度。
      猜你喜欢
      • 2021-11-20
      • 2015-09-04
      • 2018-09-05
      • 1970-01-01
      • 2018-05-05
      • 2017-09-06
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      相关资源
      最近更新 更多