Jump to content

should i also destroy $oldimg?


iPixel

Recommended Posts

My code below, i already imagedestroy($newimage)... but i'm not sure if i should be destroying $oldimg as well? Any thoughts?

 

$newimg = imagecreatetruecolor($sizeA,$sizeA) or die('Problem In Creating image');

$background = imagecolorallocate($newimg, 255, 255, 255);

imagefilledrectangle($newimg, 0, 0, $sizeA, $sizeA, $background);

$oldimg = imagecreatefromjpeg($source)or die('Problem In opening Source Image');

imagecopyresampled($newimg,$oldimg,0,$move,0,0,$sizeA,$new_height,ImageSX($oldimg),ImageSY($oldimg)) or die('Problem In resizing');

imagejpeg($newimg,$s1DIR,90) or die('Problem In saving');

imagedestroy($newimg);

Link to comment
Share on other sites

PHP will automatically clear up any resources when the script ends anyway. So technically imagedestroy should not be needed. However, If you are running a script that processes multiple images at once and takes a decent chunk of time, you might want to use it during the script to free up memory during your script, and possibly freeing up some server memory.

Link to comment
Share on other sites

Yea that's the issue i'm having, im doing this basically for 5 different sizes. So a batch i run of 250 images times out and the script never finishes. Originally I thought maybe set_time_limit was the issue, but it seems more and more like a memory_limit issue. It's now set to 256MB. So i'll try and destroy $oldimg and hope it helps.

 

Link to comment
Share on other sites

Is there a reason why need the 5 sizes for all premade.

 

I understand are already into doing what you are and I believe you are deleting your original images.

 

Well here was a thought for you.

 

When image of certain size gets called upon... have gd do a dynamic size, store to a cache folder of images that particular filename for size, cache the images. So when get a request for that size can check cache folder first, if not then execute gd resize and place into cache folder.

 

I hope you got all that. The point is why make many images if not using them all, I don't know your exact process here or what doing with them, but if have a real lot and worried about space is something to consider.

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.