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
Link to comment
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.
Link to comment
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?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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