65

I have the following GIF image file:

original gif image

I want to extract its frames (using PGM output format) using this imagemagick command:

convert brocoli.gif out%05d.pgm

But each frame has a different size.

How can I extract its frames while preserving the original gif file size?

Jeff
  • 12,555
  • 5
  • 33
  • 60
Joe Cabezas
  • 1,397
  • 3
  • 15
  • 21

2 Answers2

102

Use the -coalesce option:

convert -coalesce brocoli.gif out%05d.pgm

phreakhead
  • 14,721
  • 5
  • 39
  • 40
  • 3
    This works great! for who like me is puzzled from this option, the documentation says `Overlay each image in an image sequence according to its -dispose meta-data, to reproduce the look of an animation at each point in the animation sequence`. – gipi Sep 23 '13 at 08:59
  • 2
    I'll one-up you in terms of necromancy, joe.. @gipi I am not a gif or imagemagick expert, but my understanding of GIF is that it's a sequence of fairly independent images, where each image in the sequence can be a different size. they're layered on top of each other to produce the overall animation. This provides some compression because parts of the image which don't change are not included in each frame. Per the docs you quoted, `-coalesce` performs the layering of each frame on the whole before exporting. – orion elenzil Sep 23 '21 at 15:38
4

You can use graphicsmagick:

gm convert Test.gif +adjoin Test_image%3d.png

or

gm convert Test.gif -coalesce +adjoin Test_image%3d.png.

MrKhan
  • 154
  • 12