Can't limit the resouse used by IM

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
carol_sun
Posts: 19
Joined: 2009-11-06T00:49:59-07:00
Authentication code: 8675309

Can't limit the resouse used by IM

Post by carol_sun »

I used ImageMagick-6.7.0 to resize lots of pictures and got one large exceptional picture.
It's about 2.7MB. To resize it, Imagick++ used about 1.5GB memory.

Of course, to ensure large images do not consume all the memory on my system, I can force the image pixels to memory-mapped disk with resource limits , see the url: http://www.imagemagick.org/script/archi ... tera-pixel
But, I also don't like to see that the IO on my system is busy. So I want to skip this picture, do not resize them.

I use setrlimit() function to limit the memory and disk resouese used by IM as follow:

Code: Select all

if(signal(SIGXFSZ, handle_sigxfsz) == SIG_ERR)
        printf("can't catch sigxfsz");

struct rlimit limit;
limit.rlim_cur = 80971520;
limit.rlim_max = 80971520;
ret = setrlimit(RLIMIT_AS, &limit);

limit.rlim_cur = 20097152;
limit.rlim_max = 20097152;
ret = setrlimit(RLIMIT_FSIZE, &limit);

Magick::Blob blob(src_data, src_size);
Image image;
image.read(blob);
I could catch the SIGXFSZ signo, but after catching the SIGXFSZ, my process crashed:

Code: Select all

Program terminated with signal 11, Segmentation fault.
#0  0x080b4e56 in QueueAuthenticNexus ()
(gdb) bt
#0  0x080b4e56 in QueueAuthenticNexus ()
#1  0x080b55fc in GetAuthenticPixelCacheNexus ()
#2  0x080b5c46 in GetAuthenticPixels ()
#3  0x0820468e in ReadGIFImage ()
#4  0x080d5728 in ReadImage ()
#5  0x080a92f2 in BlobToImage ()
#6  0x0805ac70 in Magick::Image::read ()
#7  0x0804e6ba in main ()
The large image: http://www.ajrice.com/UploadFile/Image/error.gif

How can I find out the exceptional pictures and avoid resizing them? :?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can't limit the resouse used by IM

Post by magick »

Use ping(). Ping() is a lightweight method to read the image metadata without allocating the pixel cache. Check the image dimensions after you call ping() and if the image is too large, post an exception and move onto the next image.
carol_sun
Posts: 19
Joined: 2009-11-06T00:49:59-07:00
Authentication code: 8675309

Re: Can't limit the resouse used by IM

Post by carol_sun »

I know ping(), but I don't know how to decide which one is too large.
It should depend on the memory used by IM. If it consume more then 1GB, I think it's too large.
So is there some formula to calculate the memory used by IM for one image approximately?
For example, the image's dimensions is 5000*4000, can we get the size of pixel cache allocated by IM?
pete
Posts: 4
Joined: 2011-06-28T22:52:20-07:00
Authentication code: 8675308

Re: Can't limit the resouse used by IM

Post by pete »

I have a similar problem.
In file "magick/cache.c" ~ 4405 line:

Code: Select all

  cache_info=(CacheInfo *) GetImagePixelCache(image,MagickTrue,exception);
  assert(cache_info->signature == MagickSignature);
  if (cache_info == (Cache) NULL)
    return((PixelPacket *) NULL);
So, application crash, when GetImagePixelCache returns NULL. When I move "assert" after "if", application don't crach.
Function "MagickReadImageBlob()" returns image with Success, but when i try generate thumbnail by MagickThumbnailImage(), it returns image too but whole black without error information.

MagickGetImageBlob() used just after MagickReadImageBlob() fails:
325, "Application transferred too few scanlines @ warning/jpeg.c/JPEGErrorHandler/293"

I use "disk" value 512MiB in policy.xml. If i set large value, problem does'n exist.
pete
Posts: 4
Joined: 2011-06-28T22:52:20-07:00
Authentication code: 8675308

Re: Can't limit the resouse used by IM

Post by pete »

If i read "error.gif", with "disk" limit 512MiB, GetImagePixelCache() returns NULL too, but whole function MagickReadImageBlob() returns:
425, "CorruptImage `' @ error/gif.c/ReadGIFImage/1331"
Post Reply