Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image handling

Status
Not open for further replies.

cyberrate

Programmer
Dec 9, 2003
24
EE
Here is a function that i use to upload images submitted by users of a web page:
function uploadimg($image_path, $image_id, $new_w, $new_h, $compression)
{
$src_img = imagecreatefromJPEG("$image_path/$image_id.jpg");

list($width, $height, $type, $attr) = getimagesize("$image_path/$image_id.jpg");
$w_ratio=$width/$new_w;
$new_h=$height/$w_ratio;


/*if picture is wider than 540 than resize it*/
if($width > 540){
$w_ratio=$width/540;
$height=$height/$w_ratio;
$width=540;
}
/*if picture is wider than 540 than resize it*/
$dst_img = imagecreatetruecolor($new_w,$new_h);
$dst_img2 = imagecreatetruecolor($width,$height);

imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, imagesx($src_img), imagesy($src_img));
imagecopyresampled($dst_img2, $src_img, 0, 0, 0, 0, $width,$height, imagesx($src_img), imagesy($src_img));

imagejpeg($dst_img, "$image_path/s_$image_id.jpg", $compression);
imagejpeg($dst_img2, "$image_path/$image_id.jpg", 80);
chmod ("$image_path/$image_id.jpg", 0644);
chmod ("$image_path/s_$image_id.jpg", 0644);
}


This function not only uploads images to given path but also resizes it to fit in a 540 px width table if it's more than 540 px in width. Any way it works fine with photos that are less than 300 kB and works strange with others, for example it stops changing the chmod of a picture and does not create a thumb (s_ file) it supposed to.
Maybe anyone can look through it?
 
Does it get uploaded if the iamge size is greater than 300 kB .

I think you need to increase the max execution time to run php script.
This can be done by adding
Code:
set_time_limit(0) ;
at the top of your script.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Sorry, of course before calling this function i do move_uploded_files and i checked and it does get uploded, but increaseing the execution time might be a good idea, thank you.
 
And still set_time_limit(0); didn't do the trick, here is what error i get: Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 6144 bytes) in /home/htdocs/web0/html/photos1.php on line 10
 
the line 10 in the error message is this:
$src_img = imagecreatefromJPEG("$image_path/$image_id.jpg");
 
in your hp.ini you should find the following :

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30 ; Maximum execution time of each script, in seconds
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)

make these bigger and restart apache / iis.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
From the error message, it seems that the memory available to PHP at runtime needs to be increased.
This can be done by setting memory_limit to bigger value than default 8MB.
But of course the down side of this is lesser memory will be avialble to other applications running on the server.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top