How to tell if GIF is animated?

2019-07-04 16:13发布

问题:

I have this Rails app with Paperclip for image uploads -- but how do I check if the image is an animated GIF with RMagick?

回答1:

You can count the scenes associated with the image. In Rmagick that means doing something like this:

image = Magick::ImageList.new(image_file)

if image.scene == 0
  #this is not an animated gif
else
  #this is an animated gif
end