satal keto Posted November 18, 2007 Share Posted November 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77816-imagecreatefromjpeg-using-far-too-much-memory-for-what-is-needed/ Share on other sites More sharing options...
MadTechie Posted November 18, 2007 Share Posted November 18, 2007 looks fine, but your not using imagedestroy, as for a small file using a ton on memory i'll have to assume theres a problem in some code before this code is used Quote Link to comment https://forums.phpfreaks.com/topic/77816-imagecreatefromjpeg-using-far-too-much-memory-for-what-is-needed/#findComment-393849 Share on other sites More sharing options...
rarebit Posted November 18, 2007 Share Posted November 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/77816-imagecreatefromjpeg-using-far-too-much-memory-for-what-is-needed/#findComment-393853 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.