Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed memory size of 33554432 bytes exhausted (tried to allocate 4793473 bytes) #21

Closed
ranaanees opened this issue Oct 29, 2013 · 2 comments

Comments

@ranaanees
Copy link

Hii,

I am getting following error when uploading images...

Allowed memory size of 33554432 bytes exhausted (tried to allocate 4793473 bytes)

and it shows error on following code..

 /home/almotar/public_html/vendor/sybio/image-workshop/src/PHPImageWorkshop/Core/ImageWorkshopLib.php
    public static function generateImage($width = 100, $height = 100, $color = 'ffffff', $opacity = 127)
    {
        $RGBColors = ImageWorkshopLib::convertHexToRGB($color);
 
        $image = imagecreatetruecolor($width, $height);
        imagesavealpha($image, true);
        $color = imagecolorallocatealpha($image, $RGBColors['R'], $RGBColors['G'], $RGBColors['B'], $opacity);
        imagefill($image, 0, 0, $color);
 
        return $image;

Help please...

@Sybio
Copy link
Owner

Sybio commented Oct 29, 2013

Hi @ranaanees, this error is displayed when a PHP script uses too much RAM than autorized by php.ini (your PHP configuration) !

Here, your PHP config autorizes 33554432bytes (32Mb) of RAM per script which is a very small limit when using GD library for image manipulations (that uses a lot of RAM when images are big) !

You should increase this limit, either :

  • By editing your php.ini (if you have a dedicated server and access to the file) and by editing "memory_limit" value :
memory_limit = 128M;
  • Or if you don't have access to php.ini file (like a shared hosting) or if you don't want to edit your php.ini file, you can add this value in a .htaccess file :
# .htaccess
php_value memory_limit 128M

Or you can directly call a php function "ini_set" in your PHP script before image manipulation to "say" that the script is authorized to use more RAM :

<?php
// your-script.php
// ...
ini_set('memory_limit', '128M');
// ...
$layer->resizeInPixel(...);

In the examples, I choosed 128Mb of RAM maximum per PHP script.
If you are on a shared hosting, there is a limit of maximum RAM that can be increased (and sometimes you just can't increase it, so you can't use GD or your need to manage smaller images than currently) ! Check your hoster rules.

To use less RAM, a good advice is to resize your image as smaller as possible in your script before manipulating it with cropping, rotating, etc... Because, for example, rotating an image of 4000px per 3000px will consume a lot of RAM compared to an image of 1000px per 750px ^^

@Sybio
Copy link
Owner

Sybio commented Nov 12, 2013

No reply, I consider your issue fixed ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants