Page 1 of 1

SetMagickResourceLimit doesn't work

Posted: 2009-02-08T20:20:47-07:00
by codymanix
I programmed an Explorer like Application which shows thumbsnails of all image files.
The problem is that imagemagick tries to open some files which are not really images so it generated lots of temporary files.
I tried to limit the resources to 10 megabytes but it doesn't seem to change anything:

SetMagickResourceLimit(MagickLib::DiskResource, 10UL);
SetMagickResourceLimit(MagickLib::FileResource, 10UL);
SetMagickResourceLimit(MagickLib::MemoryResource, 10UL);
SetMagickResourceLimit(MagickLib::AreaResource, 10UL);
SetMagickResourceLimit(MagickLib::MapResource, 10UL);

Isn't there a way to tell the ReadImage function to return NULL if the image would be bigger than 10 megs in memory?

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T07:55:28-07:00
by magick
Try this command:
  • convert -limit memory 5mb -limit map 5mb -limit disk 5mb -size 1000x1000 xc:none null:
Does it fail with
  • convert: Cache resources exhausted `none' @ cache.c/OpenPixelCache/3814.
It does for us with ImageMagick 6.4.9-2, the latest release.

That should prove the resources are working properly. To track how resources are working in you environment, set the MAGICK_DEBUG environment variable to 'cache' to see how resources are being allocated.

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T08:43:07-07:00
by codymanix
I tried

convert -limit memory 5mb -limit map 5mb -limit disk 5mb -size 1000x1000 xc:none null: *.wmv test.png

and my windows swapping file kept growing and growing untile I cancelled the process.

Iam using ImageMagick-6.4.9-Q8, its changelog says revision is 6.4.9-2.

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T09:47:37-07:00
by magick
Try it without the *.wmv. The process exits it properly with an exception under our Windows system.

ImageMagick does not natively support all image formats. It depends on delegate libraries and programs to read some formats and to write others. The WMV format is handled by an external delegate. Because it is an external delegate we have little control over it and for these cases, the resource limits do not apply until the processing is completed by the external delegate program and ImageMagick reads in the image sequence returned by the delegate program.

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T11:47:48-07:00
by codymanix
I believe it is trying to load *all* frames of the wmv file into an imagelist.
Can I somehow specify that it just should load the first frame?

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T13:49:01-07:00
by magick
Generally you limit a read to the first image like this: 'image.gif[0]'.

Re: SetMagickResourceLimit doesn't work

Posted: 2009-02-09T19:52:22-07:00
by codymanix
Thanks for trying to help me, but I'm using the C-Interface, not the command line tools.
I've read about the ReadStream function, could I use this to stop reading if a certain number of pixels are reached?
Generelly, I find it very hard to find the required functionality and understand how things work because there seem to be almost no documentation on the ImageMagick API's.