Detect if a GIF is Animated
If you tweet an animated GIF, you'll notice that Twitter takes it and converts it to an mp4. I'd speculate that they do that conversion because an MP4 is better supported across platforms, at least in that they allow for playing/pause of the animation. And with a video you can prevent infinite looping, unlike a GIF. How can you determine if a GIF is animated though? I found a few good solutions.
Command Line with ImageMagick
ImageMagick, the amazing image manipulation library, provides a method for counting frames in a GIF:
./ImageMagick-6.9.0/bin/identify -format %n wtf.gif
The command above will provide you a count of the frames within the GIF.
var fs = require('fs'); var animated = require('animated-gif-detector'); > animated(fs.readFileSync('wtf.gif')); // true > animated(fs.readFileSync('blank.gif')); // false
The function call simply returns
false, representing if the GIF is animated. Exactly what I wanted!
As for what each library looks for, I've seen some ugly bit code I wont try to describe. If you want to determine if a GIF is animated, however, it's as easy as the utilities above!