Allowed memory size 134217728 bytes exhausted (tried to allocate 18472 bytes)

I am getting the above error on this line:

imagefill($canvas, 0, 0, imagecolorallocate($canvas, 255, 255, 255));

      

The script works fine with all types of images, but it crashes with images larger than 4000 x 3000 pixels. The image itself is only 500KB. Here's the whole code:

$canvas = imagecreatetruecolor(imagesx($source), imagesy($source));
imagefill($canvas, 0, 0, imagecolorallocate($canvas, 255, 255, 255));
imagealphablending($canvas, TRUE);
imagecopy($canvas, $source, 0, 0, 0, 0, imagesx($source), imagesy($source));
imagedestroy($source);
$quality = 100; // 0 = worst / smaller file, 100 = better / bigger file 
imagejpeg($canvas, $strPath.$p_Id.".jpg", $quality);        //----- save image
ImageDestroy($canvas);

      

+3


source to share


3 answers


No matter what size the compressed image is, your library seems to need more memory. I see you are using 128MB atm, increase it to 256 using:



ini_set('memory_limit','256M');

      

+4


source


I would override the default memory limit in PHP with:



ini_set('memory_limit', '-1');

      

+1


source


No matter what size the compressed image is, your library seems to need more memory. I see you are using 128mb atm, increase it to most

ini_set('memory_limit', 0);

      

0


source







All Articles