Forum Moderators: coopster

Message Too Old, No Replies

Using GD - memory allocation problem

trying to upload jpeg files and reduce the weight

         

Montbazin

7:33 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



Hello

I am trying to integrate a script into my dinamic PHP wepages, which helps to upload jpeg files by reucing the weicht, i.e. fol 1500 to 100 Ko.

The script works fine with "EasyPHP" on my laptop, but un my server I get an error message;

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 9088 bytes) in...

please can sombody tell me how to increase the memory allocation

Thanks, roberto

this is my function:

function jpg_upld($ffile,$ffolder,$ffname,$ffs,$qual){
$img1=imageCreateFromJpeg($ffile);
$x1 = imageSX($img1);
$y1 = imageSY($img1);
$x2 = 600;
$y2 = (($x2 / $x1) * $y1);
$img2 = imageCreate($x2,$y2);
imageCopyResized($img2,$img1,0,0,0,0,$x2,$y2,$x1,$y1);
imagejpeg($img2,"$ffolder/$ffname",$qual);
$path=$ffolder."/".$ffname;
$ffs2=filesize($path);
$ffs2=round(($ffs2 * 0.001),0);
$ffs = round(($ffs * 0.001),0);
$perc = ((100 / $ffs) * $ffs2);
$perc = round($perc,2);
echo "<br>taille: $ffs Ko / $ffs2 Ko : $perc% de la taille originale";
imageDestroy($img1);
imageDestroy($img2);
exit();
}

coopster

7:40 pm on Jan 19, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are allocating more memory than the server will allow for some reason. Perhaps these related threads will help in troubleshooting:

Serious PHP memory management problem [webmasterworld.com]
Too CPU Intensive [webmasterworld.com]

Montbazin

12:24 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Thanks for your help. well I have tried with
 memory_get_usage() 
and I have seen that the memory consumption rises quickly when it comes to the
image 
functions.

So is there something I can do to reduce this?.
I have no

include() 
functions in my script.

Thanks
roberto

coopster

2:56 pm on Jan 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If they are big images that would make sense :)

You could always increase the memory_limit [php.net] and max_execution_time.

Montbazin

6:06 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Thanks

Well the idea is that the visitors of the site can upload images coming directly from their digital cameras (between 1 and 2 Mo) without having to work on them on Photoshop or a similar software. The images which then will be stored on the website should not ecceed 50 or 100 Ko.
The site is on a commercial hosting, so I can not interveen on the PHP settings. I am therefore looking for some possibility of having working this script. It works fine under EasyPHP on my laptop.

roberto

Montbazin

6:09 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Is there a way to cope with this by reducing the "execution time" of the script, that would be a solution if possible.

coopster

11:05 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



set_time_limit [php.net]?

Montbazin

8:59 am on Jan 23, 2006 (gmt 0)

10+ Year Member



I finally found the solution following the URLs given in this thread.
The solution to change PHP memory limitations (default setting is 8 Mo), is to include the following line in the script:

ini_set("memory_limit","24M");

I don't know if this works with every provider but it worked for me.
thanks to all...
roberto