note 54524 added to function.imagecreatefromjpeg

From: Date: Thu, 07 Jul 2005 03:28:18 +0000
Subject: note 54524 added to function.imagecreatefromjpeg
Groups: php.notes 
Request: Send a blank email to php-notes+get-91563@lists.php.net to get a copy of this message
Hi, I used a script to change the size on a jpeg , everything works fine when the jpeg is small. All I want to do is check if the jpeg is too big then make it smaller. here is my code: list($width, $height) = getimagesize($filename); $size = filesize($filename); if($size > (1*1024*1024)) { $percent = round((($size)/ (1*1024*1024)), 2); // scale it so it is no more than 1 mb print "percent is: ".$percent; $new_width = $width * $percent; $new_height = $height * $percent; $image_p = imagecreatetruecolor($new_width, $new_height); // true color for best quality if($extension =="JPG" || $extension =="jpg") { $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width , $new_height , $width, $height); // Output unlink("uploads/".$_GET['name']); imagejpeg($image_p, "uploads/".$_GET['name'], 100); } } When trying to resize the jpeg it shows an error like this: <b>Fatal error</b>: Allowed memory size of 18874368 bytes exhausted (tried to allocate 3567 bytes) in <b>/home/transform.php</b> on line <b>23</b><br /> I don't know how to fix this, if anyone can help me. Thank you, ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatefromjpeg.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54524 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54524&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54524&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91563) next »