tags:

views:

92

answers:

2

I'll keep it short and simple;

is there any way of telling static GIF images apart from animated ones? I'm using C#.

Thanks

+17  A: 

Here's an article about how to determine the number of frames in a GIF animation.

Image i = Image.FromFile(Server.MapPath("AnimatedGIF.gif"));

Imaging.FrameDimension FrameDimensions = 
    new Imaging.FrameDimension(i.FrameDimensionsList[0]);

int frames = i.GetFrameCount(FrameDimensions);

if (frames > 1) 
    Response.Write("Image is an animated GIF with " + frames + " frames");
else 
    Response.Write("Image is not an animated GIF.");

And I assume you could just compare that with 1.

David Hedlund
+1 Hardcore article in a tiny font! Could you paste a snippet of the code here and link to the article as well? So that if the page or site gets deleted the answer is not lost.
amelvin
@amelvin: good idea. i see jeff has already done it, now =)@jeff atwood: props for changing the variable names to convention!
David Hedlund
+1  A: 

Wikipedia has some information on the layout of an animated GIF compared to a static one.

An animated GIF file comprises a number of images or frames to be displayed successively, each described by its own GCE (Graphic Control Extension), preceded by a header whose content by default applies to all the frames. After the header the data is stream-oriented instead of being at fixed indices, so the location of the start of a GCE depends on the length of preceding GCE(s).

ChrisF