Jump to content

[SOLVED]-ImagecreatefromJpeg + memory problem


ge00rge

Recommended Posts

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?

[code]<?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);


?> [/code]

($add is specified on another part.)

thx
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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.