bausman480 Posted June 3, 2012 Share Posted June 3, 2012 Hi, So I have a script that is supposed to crop and resize an uploaded image. One of the lines is using createimagefromjpeg(), and this line is exceeding the allotted memory limit on my shared host: "Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 10368 bytes)". This only happens whenI upload files larger than 1.5MB. I need my script to work with images up to 3-4MB. I spoke to my host and they cannot increase the memory limit. Here is the resize function that I'm using. Help? <?php function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){ $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); $source = imagecreatefromjpeg($image); // THIS is the line causing the memory error imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); imagejpeg($newImage,$thumb_image_name,90); chmod($thumb_image_name, 0777); return $thumb_image_name; }?> Help? How do I work with files largerr than 1.5MB? Is there another command that can replace imagecreatefromjpeg() that uses memory more efficiently? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/263559-createimagefromjpeg-takes-up-too-much-memory/ Share on other sites More sharing options...
kicken Posted June 3, 2012 Share Posted June 3, 2012 You could try using a different library such as [m=imagick]ImageMagick[/m] or maybe GMagick if your host has them available. Even if they don't have the ImageMagick extension they might have the cli apps which you can use exec to run separate from your script which would offload the memory usage to another process. You'll have to check with your host to see what options they have available for you to use. Running a separate program using exec is the only way to really reduce the memory usage from PHP's point of view though. Switching to another library within PHP might make small differences but ultimately processing images is just a memory intensive process and there is not much you can do about it. Quote Link to comment https://forums.phpfreaks.com/topic/263559-createimagefromjpeg-takes-up-too-much-memory/#findComment-1350703 Share on other sites More sharing options...
requinix Posted June 3, 2012 Share Posted June 3, 2012 The GD extension has two notable problems: image quality and memory usage. Switching to something else is probably your best option. Quote Link to comment https://forums.phpfreaks.com/topic/263559-createimagefromjpeg-takes-up-too-much-memory/#findComment-1350704 Share on other sites More sharing options...
bausman480 Posted June 3, 2012 Author Share Posted June 3, 2012 Thank you. So as far as I understand, switching to another image library won't help too much.. So running an external program is I guess the only option. How do you write this external program though? What language, can it still be php? Can I simply put the function above in a separate file and call it via exec? Quote Link to comment https://forums.phpfreaks.com/topic/263559-createimagefromjpeg-takes-up-too-much-memory/#findComment-1350708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.