conman90 Posted February 5, 2009 Share Posted February 5, 2009 It's a script to take an uploaded image and resize it to a thumbnail. Here's the code: <?php function resizeImage($originalImage,$toWidth,$toHeight){ list($width,$height)=getimagesize($originalImage); $xscale = $width/$toWidth; $yscale = $height/$toHeight; if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } $oldimage = $_FILES['uploadfile']['tmp_name']; resizeImage($oldimage, 100, 100); $filename = "pics/thumbnails/".$_FILES['uploadfile']['name']; imagejpeg($imageResized,$filename,100); ?> And it continually gives me this error: Warning: imagejpeg(): supplied argument is not a valid Image resource in _____ on line 26 I checked all the arguments and the one that's causing problems is $imageResized but I can't figure out why. Quote Link to comment https://forums.phpfreaks.com/topic/143891-help-i-keep-getting-an-invalid-argument-error/ Share on other sites More sharing options...
Philip Posted February 5, 2009 Share Posted February 5, 2009 Because you're not utilizing the return correctly. Try: $imageResized = resizeImage($oldimage, 100, 100); $filename = "pics/thumbnails/".$_FILES['uploadfile']['name']; imagejpeg($imageResized,$filename,100); Quote Link to comment https://forums.phpfreaks.com/topic/143891-help-i-keep-getting-an-invalid-argument-error/#findComment-755024 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.