Huge Memory Usage with GIF using Identify

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
cubetto
Posts: 2
Joined: 2013-07-17T20:16:28-07:00
Authentication code: 6789

Huge Memory Usage with GIF using Identify

Post 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.
cubetto
Posts: 2
Joined: 2013-07-17T20:16:28-07:00
Authentication code: 6789

Re: Huge Memory Usage with GIF using Identify

Post by cubetto »

Sorry, using ImageMagick 6.7.1-0 2011-08-13 Q16
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Huge Memory Usage with GIF using Identify

Post by dlemstra »

You could use image.gif[0] to access the first frame.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Huge Memory Usage with GIF using Identify

Post 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
snibgo's IM pages: im.snibgo.com
Post Reply