12

let's say that i've done a find for .gif files and got a bunch of files back. I now want to test them to see if they are animated gifs. Can i do this via the command line?

I have uploaded a couple of examples in the following, in case you want to experiment on them.

Animated GIF image

animated gif image

Static GIF Image

static gif image

Max Williams
  • 1,067
  • 2
  • 16
  • 32

3 Answers3

22

This can easily be done using ImageMagick

identify -format '%n %i\n' -- *.gif

12 animated.gif
1 non_animated.gif

identify -format %n prints the number of frames in the gif; for animated gifs, this number is bigger than 1.

(ImageMagick is probably readily available in your distro's repositories for an easy install)

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Walther
  • 596
  • 4
  • 9
9

Using exiftool:

exiftool -q -if '$framecount > 1' -p '$directory/$filename' -r -ext:gif .

Would report the paths of the GIF files that have more than one frame (in the current directory, recursively).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
5

Another way with im using the fx operator:

find . -type f -name \*.gif -exec sh -c \
'identify -format "%[fx:n>1]\n" "$0" | grep -q 1' {} \; -print

This searches the current directory and its subdirectories for .gif images running that shell command for each .gif found. If number of frames n>1 then fx prints 1, otherwise it prints 0. This is piped to grep -q 1 so -print is only executed if the previous -exec was successful.

don_crissti
  • 79,330
  • 30
  • 216
  • 245