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
https://forums.phpfreaks.com/topic/77793-solved-some-image-resizing-issues-s/
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"

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

Archived

This topic is now archived and is closed to further replies.

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