iPixel Posted January 13, 2011 Share Posted January 13, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/ Share on other sites More sharing options...
snowman15 Posted January 13, 2011 Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/#findComment-1158972 Share on other sites More sharing options...
iPixel Posted January 13, 2011 Author Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/#findComment-1158981 Share on other sites More sharing options...
iPixel Posted January 13, 2011 Author Share Posted January 13, 2011 Update : Upping the limit to 256MB and destroying the $oldimg seems to have helped to fix the issue. Next step is to run this with 5,000 images and hope it holds up. THanks! Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/#findComment-1158997 Share on other sites More sharing options...
snowman15 Posted January 13, 2011 Share Posted January 13, 2011 theoretically if you keep reallocating space, it should be fine! Enjoy! Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/#findComment-1159015 Share on other sites More sharing options...
QuickOldCar Posted January 13, 2011 Share Posted January 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224329-should-i-also-destroy-oldimg/#findComment-1159018 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.