I'm looking for a definitive answer as to whether its possible to distinguish animated GIFs from static ones before/during download. I am looking to create an extension for FireFox that funnels animated ones from static upon download. I keep hitting dead ends because the format's so old and underused now.
Is there some tell-tale indicator in the format which will help distinguish them apart?
Thanks!
Yes, there should be graphic control extensions (0xf9) to specify the delay times for each frame in an animated GIF.
- Phil
from http://en.wikipedia.org/wiki/Graphics_Interchange_Format (http://en.wikipedia.org/wiki/Graphics_Interchange_Format)
byte# hexadecimal text or
(hex) value Meaning
0: 47 49 46
38 39 61 GIF89a Header
Logical Screen Descriptor
6: 03 00 3 - logical screen width in pixels
8: 05 00 5 - logical screen height in pixels
A: F7 - GCT follows for 256 colors with resolution 3 x 8 bits/primary
B: 00 0 - background color #0
C: 00 - default pixel aspect ratio
R G B Global Color Table
D: 00 00 00 0 0 0 - color #0 black
10: 80 00 00 128 0 0 - color #1
: :
85: 00 00 00 0 0 0 - color #10 black
: :
30A: FF FF FF 255 255 255 - color #255 white
30D: 21 F9 Graphic Control Extension
30F: 04 - 4 bytes of GCE data follow
310: 01 - there is a transparent background color
311: 00 00 - delay for animation: not used
313: 10 16 - color #16 is transparent
314: 00 - end
315: 2C Image Descriptor
316: 00 00 00 00 (0,0) - NW corner position of image in logical screen
31A: 03 00 05 00 (3,5) - image width and height in pixels
31E: 00 - no local color table
31F: 08 8 LZW minimum code size
320: 0B 11 11 bytes LZW encoded image data follow
321: 00 51 FC 1B 28 70 A0 C1 83 01 01
32C: 00 - end
32D: 3B GIF file terminator
Animated GIF
byte# hexadecimal text or
(hex) value Meaning
0: 47 49 46
38 39 61 GIF89a Header
Logical Screen Descriptor
6: 90 01 400 - width pixels
8: 90 01 400 - height pixels
A: F7 - GCT follows for 256 colors with resolution 3 x 8bits/primary
B: 00 0 - background color #0
C: 00 - default aspect ratio
D: Global Color Table
:
30D: 21 FF 0B Application Extension
310: 4E 45 54
53 43 41
50 45 32
2E 30 NETSCAPE2.0
31B: 03 01 - data follows
31D: FF FF - loop animation
31F: 00 - end
320: 21 F9 04 Graphic Control Extension frame #1
323: 08 - no transparency
324: 09 00 - 0.09 sec duration
326: 00 - no transparent color
327: 00 - end
328: 2C Image Descriptor
329: 00 00 00 00 (0,0) - scan pixels from left top...
32D: 90 01 90 01 (400,400) - ...to right bottom
331: 00 - end
332: 08 8 LZW min code size
333: FF 255 255 bytes LZW encoded image data follow
334: data
433: FF 255 255 bytes LZW encoded image data follow
data
:
92BA: 00 end
92BB: 21 F9 04 Graphic Control Extension frame #2
: :
153B7B:21 F9 04 Graphic Control Extension frame #44
:
15CF35:3B 1 429 301 File terminates
That's great, really useful thanks!