Anne Quinn
Anne Quinn

Reputation: 13002

ImageMagick: How to apply one gif's per-frame delays to another gif?

I have a workflow where I take gifs from a client, convert them from gif to sprite sheets (png) I can work on, then convert them back to gifs to send back. The Client's frame delays in their gifs are important though, so I need to preserve them.

Is there a way I can grab the frame delays in one gif, and apply them to another gif, using ImageMagick commandline utilities? I'm doing these through a .bat batch file on windows. The gifs have the same dimensions and frame counts.

Upvotes: 2

Views: 539

Answers (1)

fmw42
fmw42

Reputation: 53089

In Imagemagick 6, you can use the string format %T to get the animation delay. Put it into a variable and then use the variable for the delay of the next animation. See https://imagemagick.org/script/escape.php

convert -delay 100 rose: rose: rose: -loop 0 anim.gif

convert anim.gif -format "%T\n" info: | head -n 1
100

Note that without piping to head -n 1, Imagemagick will repeat the delay once for each frame.

For Imagemagick 7, use magick rather than convert. In Windows .bat, double the % to %%.

For Windows you may need to find an equivalent tool to head -n 1 or just parse the text output from %T to extract only one value from all the repeats for each frame.

Upvotes: 2

Related Questions