Jump to content

Resize large image


satal keto

Recommended Posts

Hello I am trying to get some code which will resize images which are uploaded to my website using a form.

The code I am using to resize the images atm is

function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbHeight)
{
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);

$ratio = $origHeight / $thumbHeight;
$thumbWidth = $origWidth / $ratio;
$dst_img=ImageCreateTrueColor($thumbWidth,$thumbHeight);
#imagecopyresampled($dst_img,$srcImg,0,0,0,0,$thumbWidth,$thumbHeight,$origWidth,$origHeight);
imagecopyresized($dst_img,$srcImg,0,0,0,0,$thumbWidth,$thumbHeight,$origWidth,$origHeight);
imagejpeg($dst_img,$thumbDirectory . "/" . $imageName);
imagedestroy($dst_img);
}

The problem is when ever I try to run this code it is saying...

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 3264 bytes) in K:\WOS Stuff\www\sb\adminPhotos.php on line 5
where line 5 is
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");

I was wondering whether anyone had any idea's of some how that I would be able to resize the images without causing this error?

Link to comment
https://forums.phpfreaks.com/topic/77952-resize-large-image/
Share on other sites

Well it could also be that your script grabs just over the 8MB default memory limit of PHP. (although i think php5 has a default limit of 300mb).

 

What version of php are you running?

 

Run phpinfo() and check your version, also check your memory limit. You can edit memory_limit in your php.ini file to fix this, or you could edit your .htaccess file and add this line:

php_value memory_limit 24M for a quick fix, if thats the problem

Link to comment
https://forums.phpfreaks.com/topic/77952-resize-large-image/#findComment-394600
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.