Jump to content

Help.. I Keep getting an Invalid Argument Error


conman90

Recommended Posts

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.

 

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.