Ubuntu – command to get the number of frames in a gif

command linegifimage processingimagemagick

Is there a command to get the number of frames in a gif?
I have some gifs, and I want to convert them into arrays, but I want to limit the array, and structure of the array based on the number of frames in any random gif I happen to feed my program. I was thinking imagemagick might have such an option, but i haven't found it yet.

Best Answer

If you have ImageMagick installed, you can use its identify command as follows

identify /path/to/image.gif

You'll get details of each frame.

As suggested by steeldriver, you can get the number of images in the sequence directly using the %n output format specifier, however rather annoyingly it appears to print it once for each image. To get a single number you could do

identify -format "%n\n" path/to/file.gif | head -1