SetMagickResourceLimit doesn't work

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
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

SetMagickResourceLimit doesn't work

Post 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?
Last edited by codymanix on 2009-02-10T16:19:13-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SetMagickResourceLimit doesn't work

Post 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.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: SetMagickResourceLimit doesn't work

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SetMagickResourceLimit doesn't work

Post 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.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: SetMagickResourceLimit doesn't work

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SetMagickResourceLimit doesn't work

Post by magick »

Generally you limit a read to the first image like this: 'image.gif[0]'.
codymanix
Posts: 19
Joined: 2008-02-20T20:49:46-07:00

Re: SetMagickResourceLimit doesn't work

Post 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.
Post Reply