Jump to content

Archived

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

ge00rge

[SOLVED]-ImagecreatefromJpeg + memory problem

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Ok,I used [code]ini_set( "memory_limit", "200M" );[/code] to change the limit to 200MB,I hope it's not too much!Thanks DocSeuss  :)

Share this post


Link to post
Share on other sites

×

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.