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
Share on other sites

Change

 

$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");

 

to

 

$srcImg = imagecreatefromjpeg("YOUR_PATH/".$imageName);

 

But replace YOUR_PATH with your direct path. Because there could be an error with the $imagedirectory variable.

 

Just a thought

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.