Jump to content


Photo

[SOLVED]-ImagecreatefromJpeg + memory problem


  • Please log in to reply
4 replies to this topic

#1 ge00rge

ge00rge
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 August 2006 - 03:04 PM

hi all,
I'm using the script below to create thumbnails of uploaded images.The problem is when a file is ~1.5mb I get this error: "Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to allocate 13056 bytes) in /var/www/hosts/mysite/http/imgup.php on line 29" .Is there a filesize limit when using ImagecreatefromXXX?

<?php

$n_width=100; // Fix the width of the thumb nail images
$n_height=100; // Fix the height of the thumb nail imaage
$tsrc= "/var/www/hosts/mysite/http/img/" . $HTTP_POST_FILES['userfile']['name']; // Path where thumb nail image will be stored



if ($HTTP_POST_FILES['userfile']['type']=="image/gif"){
$im=ImageCreateFromGIF($add);
$width=ImageSx($im);              // Original picture width is stored
$height=ImageSy($im);            // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

if (function_exists("imagegif")) {

ImageGIF($newimage,$tsrc);
}

elseif (function_exists("imagejpeg")) {
Header("Content-type: image/jpeg");
ImageJPEG($newimage,$tsrc);
}

chmod("$tsrc",0777);
}
if($HTTP_POST_FILES['userfile']['type']=="image/jpeg"){
$im=ImageCreateFromJPEG($add);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc);
}
chmod("$tsrc",0777);


?>

($add is specified on another part.)

thx

#2 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 15 August 2006 - 05:11 PM

php does have a memory limit that can be set in the ini file, it is possible to up this limit on a temp basis with ini_set( "memory_limit", "200M" ) change the memory value to what is appropriate. After the script executes the original value will be restored.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#3 ge00rge

ge00rge
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 15 August 2006 - 05:49 PM

You're right DocSeuss,the memory_limit is set to 16M,but I don't have access to php.ini to change the limit.I tried using .htaccess file,but it didn't work.Is there any way of "clearing" the memory after the script has finished its work?



#4 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 16 August 2006 - 04:33 AM

ini_set('$variable to change, $value to change to) is a native php function that allows you to change ini variables during the run of the script. The values revert back to the original value after the script with the ini_set() function finishes.

"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#5 ge00rge

ge00rge
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 16 August 2006 - 05:12 PM

Ok,I used
ini_set( "memory_limit", "200M" );
to change the limit to 200MB,I hope it's not too much!Thanks DocSeuss  :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users