1

On Linux (Ubuntu), I was able to append two animated gifs (same sizes, same number of frames) with this command:

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

You can also find this command here: Animation Modifications.

On Windows this command does not work. It generates errors:

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.

What should I change in order to use this command on Windows ?

This command does not generate errors but it does not append the images:

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
18
  • I think you need to replace double slashes, where acting as line continuation characters, with carets (^). And remove double backslashes before opening and closing parentheses. And replace single quotes with double quotes. Mar 26, 2018 at 10:13
  • @MarkSetchell Thanks. I've tried that, unsuccessful. Mar 26, 2018 at 10:15
  • Please edit your question to show what you tried, thank you. Also look at bottom of this answer... stackoverflow.com/a/49358428/2836621 Mar 26, 2018 at 10:16
  • @MarkSetchell I've just edited. Thanks for the link. Mar 26, 2018 at 10:17
  • I don't think you need carets before parentheses. Sorry, I only have limited Windows knowledge. Mar 26, 2018 at 10:18

3 Answers 3

3

Quoting is different on Windows from Unix. Here are some ideas on how to convert from Linux quoting to Window quoting. Note that most online ImageMagick examples are given with Linux style quoting, so this will be especially relevant to any Windows users.


1. Line Continuation

On Linux, the backslash is used as a line continuation character, but Windows uses a caret (^), so this (Linux):

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

becomes this (Windows):

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

2. Replace single quotes with double quotes

On Linux, parameters can be quoted in single quotes, but on Windows, double quotes are required, so this (Linux):

convert 'image with spaces.png' info:

becomes this (Windows):

convert "image with spaces.png" info:

3. Some characters need escaping removed when going to Windows

On Linux, some characters need escaping by preceding them with backslashes, such as (, ), ! but this is unnecessary on Windows, so this (Linux):

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

becomes this (Windows):

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

4. Double up percent signs

Double up percent signs when going from Linux to Windows, so this (Linux):

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

becomes this (Windows):

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

5. Some characters need escaping added when going to Windows

Some characters need a caret adding before them to escape them when moving to Windows, for example |, &, > and <, so this (Linux):

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

becomes this (Windows):

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

6. Watch out for comments

The hash sign (#) introduces comments in Linux, and these are probably best removed and placed elsewhere, so this (Linux):

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

could become either of these (Windows):

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

If you are aware of any other cases, or that any of mine are incorrect, or could be better explained, please let me know via a comment and I will try to keep the list correct as a reference for other folk.

2

I would probably simulate the "+append" with something like this...

Read in the file1 GIF, coalesce, and set its page geometry to extend it to double its width to the right. Coalesce again to create that additional canvas area.

Then include the "null:" to separate the file1 frames from the file2 frames.

Then read in the file2 GIF and coalesce it.

Finish by setting the gravity to east and using "-layers composite" to composite each file2 frame over the extended area of its partner file1 frame. Set the delay and "-loop 0", and name the output file.

A command to do that would look something like this...

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

To use a command like this in a BAT script, make the single percent signs "%" into doubles "%%".

5
  • What do we have to change to append vertically ? 0+0%[fx:w*2]x%[h] and gravity south? Mar 26, 2018 at 16:32
  • Nope... I didn't find how to append vertically. Any idea please ? Mar 26, 2018 at 16:46
  • You can set the page geometry so the "file1.gif" frames are doubled in height by using "-set page %[h]x%[fx:h*2]+0+0 -coalesce". Then using "-gravity south" and "-layers composite" should composite the "file2.gif" frames over the extended lower area "file1.gif" frames. The result would be like "-append" vertically.
    – GeeMack
    Mar 26, 2018 at 17:37
  • Thanks. It works. But isn't it rather %[w]x%[fx:h*2]+0+0 instead of %[h]x%[fx:h*2]+0+0 ? (In my case width=height so there's no difference). Mar 26, 2018 at 17:53
  • Yes. My mistake. The "w" is the width and the "h" is the height in an FX expression.
    – GeeMack
    Mar 26, 2018 at 18:00
1

Still I don't know how to fix the command. Let me provide the Linux solution given here for Windows.

Here it is:

1) separate frames of file1.gif in files a-0001.gif, ...:

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

2) separate frames of file2.gif in files aa-0001.gif, ...:

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

3) append frames side-by-side (using %~nxf to get a relative path - important):

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

4) join the appended frames:

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.