How do I limit disk usage?

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
chris

How do I limit disk usage?

Post by chris »

Hello,

I am experiencing a problem where processing a file with a very large available pallet (approx. 200" x 200") is consuming all of the available memory on my web server.

We use version 6.4.6-Q16 installed on a Windows server. I changed the following keys in the config.xml file in the
\config directory:
<configure name="MAGICK_MEMORY_LIMIT" value="32000000"/>
<configure name="MAGICK_MAP_LIMIT" value="64000000"/>
<configure name="MAGICK_AREA_LIMIT" value="64000000"/>
<configure name="MAGICK_DISK_LIMIT" value="500000"/>
<configure name="MAGICK_FILE_LIMIT" value="20"/>

This, however, did NOT limit the file's disk consumption. The temporary file grew to 810MB. I DO want the file to fail and throw an error since it isn't usable to us.

Please help. How do I limit the disk usage? What I've done so far doesn't seem to be working.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I limit disk usage?

Post by magick »

Type
  • convert -list resource
Does it report values that match your limits (e.g. a File limit of 20)?

You could always set environment variables, e.g. MAGICK_MEMORY_LIMIT.

Have you read http://www.imagemagick.org/script/resources.php and http://www.imagemagick.org/script/architecture.php? If you set a low disk limit, ImageMagick exits if the limit is reached.
chris

Re: How do I limit disk usage?

Post by chris »

Yes, the setting match my inputs. Disk is set to 488kb. HOWEVER, I'm seeing a file in the temp directory that is 810,005 KB. The Disk setting apparently has no effect. What am I doing wrong?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I limit disk usage?

Post by magick »

The disk limit is in megabytes. Try reducing its value.
chris

Re: How do I limit disk usage?

Post by chris »

I set it to a value of 1 in configure.xml, which should be 1MB. Still no luck. The file size made it up to 810,005KB.
chris

Re: How do I limit disk usage?

Post by chris »

Further, I added those keys to the System Environment Variables and still, nothing changed.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I limit disk usage?

Post by magick »

Which file size? Disk limits only apply to the pixel cache, not the final output image. Add -debug cache to your command line to track the size of the pixel cache on disk.
chris

Re: How do I limit disk usage?

Post by chris »

The temp file size in c:\windows\temp. There are actually about 5 separate magick-*.tmp files created. 4 of the 5 are small, but there is always the one file that grows to 810MB. I'm using image magick to programmatically resize the image file and create a thumbnail. Here is the C#code:

Code: Select all

public const int MAX_THUMBNAIL_WIDTH = 256;
        public const int MAX_THUMBNAIL_HEIGHT = 256;
        public const String THUMBNAIL_FORMAT = ".jpg";
// Load into ImageMagick image
                Stream byteStream = new MemoryStream(asset.AssetData); //asset.AssetData is a byte array representing the file
                try
                {
                    MagickNet.Image image = new Image(byteStream);
                    // If the current image is small, don't enlarge it.
                    int newWidth = Math.Min(image.Size.Width, MAX_THUMBNAIL_WIDTH);
                    int newHeight = Math.Min(image.Size.Height, MAX_THUMBNAIL_HEIGHT);
                    
                    Blob thumbnail = new Blob();
                    if (fileExtension.Equals("psd"))
                    {
                        // Photoshop file must be converted before it's resized
                        image.Write(thumbnail, "JPG");
                        image = new Image(thumbnail);
                    }

                    // Resize to thumbnail, then save to thumbnail format
                    image.Resize(new Geometry(newWidth, newHeight));
                    image.Density = new MagickNet.Image.Resolution(72.0, 72.0);
                    image.Write(thumbnail, "JPG");

                    // Save blob back into Asset object
                    asset.PreviewThumbnail = thumbnail.ToArray();
                }
The image that is causing a problem is an eps file that is approximately 200" high and 200" wide. Do I need to convert from .eps to a .jpg before resizing to a thumbnail?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I limit disk usage?

Post by magick »

EPS are first preprocessed by Ghostscript. ImageMagick limits only apply to the pixel cache, not intermediate files created by delegate libraries or utilities. You can write a preprocessor program that reads the dimensions from an EPS program and reject it if its too large-- before you call the ImageMagick API.
Post Reply