bluebutterflyofyourmind Posted November 18, 2007 Share Posted November 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted November 18, 2007 Author Share Posted November 18, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 18, 2007 Share Posted November 18, 2007 Are you testing this on local server or Online server. First check if you have a directory named Orig. If it is on online server check permissions on the folder where the images are uploaded ... is it set correctly. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2007 Share Posted November 18, 2007 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" Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted November 18, 2007 Author Share Posted November 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2007 Share Posted November 18, 2007 Looking further down in your code, $Orig is where you create the image from $uploadfile, but you are using $uploadfile in the imagecopyresampled() instead $Orig. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.