creating thumbnails, imagecopyresampled() in php

I am trying to create thumbnails in php. I have attached the code which works great except the files with bigger dimensions (width > 1600 aprox., Height > 1600 aprox.)
When I try to upload a wider image, it creates a blank thumbnail.
Any ideas/suggestions?
if(isset($_POST['submit']))
   {
     include_once('conn.php');
   	 $id = $_POST['id'];
	  
     $new_height=100;
     $new_width=150;
     $allowed_types = array( 
     'image/pjpeg', 
     'image/gif', 
     'image/png', 
     'image/jpeg'); 
 
     if(in_array($_FILES['thefile']['type'], $allowed_types)) 
     {
 
       copy ($_FILES['thefile']['tmp_name'], $_FILES['thefile']['name']) or die     ("Could not copy");
       $imagefile=$_FILES['thefile']['name'];
       list($width, $height) = getimagesize($_FILES['thefile']['name']);
		 
	   if($height){
	   $percentage = round(($new_width * 100/$width));
	   $new_height = ($height*$percentage/100);
	   }
	   
       $image_p = imagecreatetruecolor($new_width,$new_height);
       if ($_FILES['thefile']['type'] == "image/gif") 
       {
           $img = @imagecreatefromgif($imagefile);
           imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
           $thename=$_FILES['thefile']['name'];
           $thenames="thumb$thename";
           $location="thumbs/$thenames";
           imagegif($image_p,$location, 100);
 
       }
       else
       {
         $img = @imagecreatefromjpeg($imagefile);
         imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
         $thename=$_FILES['thefile']['name'];
         $thenames="thumb$thename";
         $location="$thenames";
         imagejpeg($image_p,$location, 100);
       }
	    $sql = "UPDATE `tbl_people` SET image ='$thename', thumbnail ='$thenames' WHERE people_id = $id ";
		  
		  $rs = mysql_query($sql,$cn);
	      header("Location:../people_list.php");
     }
	 
	 
     else
     {
       print "<br>Please check your file size and file format (Only Gifs and Jpegs are supported). <br /> Back to <A href='../people_update.php?id=$id'>Upload photo</a>";
     }
   }
 
 mysql_close($cn);

Open in new window

martyjeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FreakTrapCommented:
Try editing the two instances of the attached lines to remove the @.


This should give you an error now when uploading the images.  Something along the lines of "Insufficient memory available for allocation."  AFAIK, this is an issue with the restrictions placed upon the PHP executable by your hosting provider; however, if this is not the error you receive or if you are hosting the server yourself, please post the new error output after making the above changes.
<?php
     $img = @imagecreatefromjpeg($imagefile);
?>
becomes:
<?php
     $img = imagecreatefromjpeg($imagefile);
?>

Open in new window

0
martyjeAuthor Commented:
Didn't do anything. same results. I think the problem is in imagecopyresampled() function. Not exactly sure what is it but this is where it's acting ODD.
0
martyjeAuthor Commented:
Ok, yea got the error running the script:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 1616 bytes) in /test/upload.php on line 107
0
Roger BaklundCommented:
To allow PHP to use as much memory as it needs, use the below code at the start of your script:
ini_set('memory_limit',-1);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
martyjeAuthor Commented:
Thanks much, sorry for the late grading :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.