Jump to content

imagecreatefromjpeg() using far too much memory for what is needed


satal keto

Recommended Posts

I am creating a website for a friend of mine who is a model.

One of the things that she would like for the website to do, is to allow her to choose a file that she wants on the website and then for using a simple form on the website to upload the file and then make a thumbnail of that picture.

 

The code I am using for the creation of the thumbnail 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);
imagejpeg($dst_img,$thumbDirectory . "/" . $imageName);
}

 

When I am running the script I am recieving the error message

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 9792 bytes) in /home/fhlinux159/s/sarah.satalketo.co.uk/user/htdocs/adminPhotos.php on line 5

(Line 5 being "$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");")

Now considering the original file was 426KB I think it using up 32MB is a little silly.

So I was wondering whether I have made an error somewhere and this is causing the massive usage of memory.

Link to comment
Share on other sites

You can either try to change the amount of temp memory used for this type of stuff, by asking your host, or doing with:

ini_set("memory_limit","19148K");

, either way if you look in php.ini (or in phpinfo() in 'PHP Core' as 'memory_limit') it is possible to see what it's currently set at.

 

 

From doing some reading, i've just enlarged an image to 3000x2859 pixels at 150 dpi (not too many colours), in Gimp it's 66.7MB when open (decompressed), yet when compressed as a jpeg it's 860KB at 85% compression, 650KB at 75%, and 430.6 at 50%. So when you say

Now considering the original file was 426KB I think it using up 32MB is a little silly.
, could be also considered the same, because your using the wrong bit of information!

 

Remember using gd with php on a (basic host) server is tailored for small web graphics, it's not on a speedy graphics pc managed in a C app.

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.