Memory Allocation Error

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Memory Allocation Error

Post by webdevsoup »

Hey everyone, question for those of you out there that are geniuses (I'm a newbie to IM). I am running ImageMagick-6.5.4.7-5.el6.x86_64 and CentOS 6.0 Final. When running a script to create thumbnails, I am getting the following errors:

Code: Select all

exception 'ImagickException' with message 'Memory allocation failed `/tmp/magick-XXIaQCm8' @ psd.c/ReadPSDImage/1035' in /home/opmadb/html/metaprocess/testrender.php:57
Stack trace:
#0 /home/opmadb/html/metaprocess/testrender.php(57): Imagick->__construct('/home/opmasan/m...')
#1 {main}
testrender.php:57-66 is as follows:

Code: Select all

$thumb=new Imagick($local_path);
			$thumb->flattenImages();
			$thumb->setImageColorspace(Imagick::COLORSPACE_SRGB);
			//Scale the image
			$thumb->thumbnailImage(128,128,true,false);
			$thumb->setImageFormat("png");
			$thumb->stripImage();
			
			//Write the new image to a file
			$thumb->writeImage('/home/metathumbs/'.$image_data->thumb);
When I look in to the error a little bit more, line 1035 in ImageMagick is something to do with the layers in the photo.

Examples can be gotten here (File size is 46MB compressed):

http://www.sfwdesign.com/sites/all/imag ... pd.psd.zip

Thanks for any help.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Memory Allocation Error

Post by magick »

Perhaps you need to increase the maximum amount of memory a script may consume for PHP. The default may be as low as 8MB. In our php.ini script file, we use
  • memory_limit = 128M
If you cannot increase the limit, set your memory resource limit to say 2MiB (not sure how this is done in IMagick, from the command line its -limit memory 2MiB). If an image or a set of images exceed this limit, all subsequent images are cached to disk to reduce the memory resource consumption.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Memory Allocation Error

Post by webdevsoup »

magick wrote:Perhaps you need to increase the maximum amount of memory a script may consume for PHP. The default may be as low as 8MB. In our php.ini script file, we use
  • memory_limit = 128M
If you cannot increase the limit, set your memory resource limit to say 2MiB (not sure how this is done in IMagick, from the command line its -limit memory 2MiB). If an image or a set of images exceed this limit, all subsequent images are cached to disk to reduce the memory resource consumption.
I have already done this. My memory is at, I believe, 256M. The issue is not with the size, because I have larger images that process fine, for instance 84MB that process through normally, with no errors.
slange
Posts: 1
Joined: 2013-12-03T10:24:33-07:00
Authentication code: 6789

Re: Memory Allocation Error

Post by slange »

Hello,
i have the same problem using ImageMagick 6.5.4-7 2012-05-07 Q16 OpenMP.

Code: Select all

2013-12-03T18:22:37+01:00 0:01 3.490u 6.5.4 Coder identify[19382]: psd.c/ReadPSDImage/1032/Coder
    allocation of image for layer 4 failed
2013-12-03T18:22:37+01:00 0:01 3.490u 6.5.4 Exception identify[19382]: psd.c/ReadPSDImage/1035/Exception
  Memory allocation failed test.psd

Code: Select all

identify -verbose -debug all "./test.psd"[5]
Is there any solution so far?

Regards
Post Reply