Pixel cache allocation failed

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
richardruiter

Pixel cache allocation failed

Post by richardruiter »

Hi,

While developing my applications which uses the imagick component to generate organograms.
This worked fine untill a few days ago. I'm sure nothing changed in the code!
We get this error:

Code: Select all

Fatal error: Uncaught exception 'ImagickException' with message 'Pixel cache allocation failed `'' in /var/www/ssi/classes/Draw/label.php:56 Stack trace: #0 /var/www/ssi/classes/Draw/label.php(56): Imagick->drawimage(Object(ImagickDraw)) 
When i search this on google nothing comes up except for some xml config files which contains the text.

It was driving me nuts and i thought that the problem was on the server (CentOS).
So i reinstalled the complete server (Ubuntu) an suprise suprise the same error.

That made me think it really must be the code... maybe somebody can help me out or give an alternative.
Here's the specific code:

Code: Select all

              
$labeltxt = new ImagickDraw();
$labeltxt->setFont(SITE_PATH_FONTS . $this->getFont());
$labeltxt->setFontSize($this->getFontsize());
$labeltxt->setFillColor($this->getFontcolor());
$labeltxt->annotation(0, $this->getFontsize()-3, $options["label"]);
if ($options["decoration"]) {
        $labeltxt->setTextDecoration($options["decoration"]);
}
$metrics = $this->getImageobject()->queryFontMetrics($labeltxt, $options["label"]);
$labelw = ($options["options"]["width"]) ? r($options["options"]["width"]) : $metrics["textWidth"];
$labelh = $metrics["textHeight"]-3;

$this->getImageobject()->newImage($labelw, $labelh, "none");
$this->getImageobject()->drawImage($labeltxt);
Regards,
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Pixel cache allocation failed

Post by magick »

The only time that exception message is thrown is when the image width by height exceeds multiple terabytes of pixels. Add debugging to your code and verify the label width and height are not negative and of a reasonable value (e.g. 640x480).
richardruiter

Re: Pixel cache allocation failed

Post by richardruiter »

Thanks! That was it!

:lol:
Post Reply