I've found a work-around. I first test if the image file is greater than 5MB. If so, then it loads it setting resource limits, as here:
Code: Select all
$im = new Imagick();
$im->setResourceLimit(Imagick::RESOURCETYPE_MEMORY,1);
$im->setResourceLimit(Imagick::RESOURCETYPE_MAP,1);
$im->readImage($source_image_file);
I'm only guessing at 5MB (6MB seems to work without resource limits, but I wanted to set the bar a bit lower just in case).
This points at a different problem: I wanted to make the conditional code execute when an exception error is thrown by Imagick, but try as I might, I couldn't succeed at it. It has no problem with just creating the object, like this:
Doing that isn't a problem. Doing anything with the Imagick object AFTER initializing it with an image file then causes the routine to crash (e.g. resize, get geometry, etc.) Putting that into a try/catch block did not work. Putting it into a try/catch block would be ideal, because then I'm not simply relying on an arbitrary file size (5MB in this case) as the litmus test for conditionally branching to setting resource limits that force the work to be done on disk and not in RAM.
Is there a magic-bullet coding solution for this? Following the prescriptions here:
https://stackoverflow.com/questions/158 ... -error-php
...did not work. Instead of proceeding to the "catch" block, the routine simply falls over. And I simply used:
Code: Select all
$im = new Imagick($filename);
$geo = $im->getImageGeometry();
...in the "try" block; the routine simply stops when the $geo line is executed (i.e., it doesn't advance to the "catch" block.)
Any suggestions?