Page 1 of 1

Huge Memory Usage with GIF using Identify

Posted: 2013-07-18T08:02:06-07:00
by cubetto
Hi guys,

We are running a large batch job resizing images from 16M Pages and found this jewel of a GIF that makes ImageMagick use several GBs of RAM in a few seconds: https://dl.dropboxusercontent.com/u/214 ... storia.gif

All we need to do is resize first frame so i was wondering if there is any way to tell ImageMagick to just load the first frame. We are using php and there seams to be no way to load just the first frame from that API.

In the meanwhile, to avoid this kind of issues we tried to use identify to see if a GIF has more than 1 frame (to see if it´s animated) but it also loads the memory just by running "identify https://dl.dropboxusercontent.com/u/214 ... storia.gif".

We worked around this by reading the first 100k to see if the gif is animated like this:

Code: Select all

while(!feof($fh) && $count < 2){
  $chunk = fread($fh, 1024 * 100); //read 100kb at a time
  $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk, $matches);
}
And then using GD's imagefromgif which only gets the first frame but it would be great for us to be able to make it simpler and using only IM.

Any help appreciated.

Re: Huge Memory Usage with GIF using Identify

Posted: 2013-07-18T08:03:01-07:00
by cubetto
Sorry, using ImageMagick 6.7.1-0 2011-08-13 Q16

Re: Huge Memory Usage with GIF using Identify

Posted: 2013-07-18T08:07:44-07:00
by dlemstra
You could use image.gif[0] to access the first frame.

Re: Huge Memory Usage with GIF using Identify

Posted: 2013-07-18T08:42:17-07:00
by snibgo
Yes, the first frame (or any frame) can be resized, eg:

Code: Select all

convert in.gif[0] -resize 10% out.png
How many frames are there?

Code: Select all

identify -ping -format "%n" in.gif
List the frames:

Code: Select all

identify -ping in.gif