Jump to content

[SOLVED] Some image resizing issues :S


Recommended Posts

hey there.  I'm just trying to create a simple thumbnail from an image that has just been uploaded via a form.  I'm getting the error "Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home...."  when i try to use imagecopyresiz() or imagecopyresample().  i feel there is something pretty simple i'm doing wrong but can't quite figure it out on my own.  any help would be great!

 

code for creating thumbnail:

			$uploaddir = 'Orig/';
			$uploadfile = $uploaddir . basename($_FILES['imagefile']['name']);

			list($width, $height, $type, $attr) = getimagesize($uploadfile);


			if($filetype == "image/jpeg"){
				//header("Content-Type: image/jpeg");
				$Orig = imagecreatefromjpeg($uploadfile);

			}
			else if($filetype == "image/png"){
				//header("Content-Type: image/png");
				$Orig = imagecreatefrompng($uploadfile);

			}
			else{
				echo "ERROR ERROR ERROR!!!!!!!!!!<BR>";
			}

			$thumb = imagecreatetruecolor(100,100);

			imagecopyresampled($thumb,$uploadfile,0,0,0,0,100,100,$width,$height);

			echo "<img src=".$uploadfile." /><BR>";
			echo "<img src=".$thumb." /><BR>";

 

i've commented out the header lines cause they seem to cause some major issues....i'm not exactly sure how to use them either so any guidance on that would also be appreciated!  thanks again.

Link to comment
Share on other sites

Your if/elseif logic that tests for the $filetype blindly continues execution when the type does not match "image/jpeg" or "image/png".

 

You need to prevent the resizing code from executing if there was not match and you need to echo out what $filetype actually contains. Either it is empty if the upload failed (you are checking the upload ['error'] element?) or it could contain a type your code does not expect, such as "image/pjpeg"

Link to comment
Share on other sites

earlier in the code i make sure that the user can only upload a jpeg or png thus those if/elseif statements shouldn't cause a problem.  i think it's in my imagecreatetruecolor function where things go wrong.  i'm apparently passing it unknown input types but i'm not sure how to create the resource image and destination image so that this error does not occur

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.