Allowed Memory Size
Posted by Esvon Support on 16 April 2007 01:56 PM
Converting (resampling) an image larger than a certain size can cause PHP to exceed its allowable memory limit:

Fatal error: Allowed memory size of XXXXXXXX bytes exhausted (tried to allocate XXXX bytes) in /path/to/website/inc/class.image_resizer.php on line XXX

This happens because converting a compressed image requires the image to be held in memory, uncompressed, at the original size and new size simultaneously. 10:1 compression is not unusual for JPEG images, so this may require more memory than you might expect.

For example, 2-megapixel Olympus digicam takes 1600x1200 x 24-bit-per-pixel pixel images. For the color depth let's call it "three bytes" instead of "24 bits" per pixel. When the digicam is set at the default "High" quality level, an average-sized image occupies about 500K of storage space.

Despite only being "0.5 MB images", each image requires

3 x 1600 x 1200 = 5,760,000 bytes = 5.76 MB

in memory.

Using this as a guide, if your images are using the same level of jpeg compression (probably not, but you can do the math), then a 2 MB image might need over 20 MB(!) if memory.

Depending on your circumstances, some solutions might be

* Change the image conversion method (use ImageMagick).
* Increase PHP's memory size limit.
* Reduce the size of your full-size images before uploading.

We recommend ImageMagick usage. As an external process, it's not subject to PHP's memory limits and it can be faster as well.

If you can't use ImageMagick by some reason,
to increase PHP's memory size limit, you can add line
ini_set('memory_limit','30M');
into inc/application.php

OR line
php_value memory_limit 30M
into .htaccess

OR edit php.ini and restart web server.

Comments (0)
Help Desk Software by Kayako Fusion