Hi there,
I have the following script:
<?
error_reporting(E_ALL);
if(!isset($filename)) die('filename ?!');
if(!isset($type)) $type = '';
switch ($type) {
case 'small': # Output a thumbnail (200 x 150)
GenJPG($filename, 200, 150);
break;
case 'medium': # Output a medium sized image (800 x 600)
GenJPG($filename, 800, 600);
break;
default: # Output original image
GenJPG($filename);
}
?>
<?
function GenJPG($inFileName, $inWidth = 0, $inHeight = 0) {
if (!$inWidth || !$inHeight)
$theImage = ImageCreateFromJPEG("media/$inFileName");
else {
if (is_file("media/$inWidth$inHeight-$inFileName"))
$theImage = ImageCreateFromJPEG("media/$inWidth$inHeight-$inFileName");
else {
$tmpImage = ImageCreateFromJPEG("media/$inFileName");
$theImage = ImageCreate($inWidth, $inHeight);
ImageCopyResized($theImage, $tmpImage, 0, 0, 0, 0, $inWidth, $inHeight, ImageSX("media/$inFileName"), ImageSY("media/$inFileName"));
ImageDestroy($tmpImage);
ImageJPEG($theImage, "media/$inWidth$inHeight-$inFileName", 90);
}
}
Header("Content-type: image/jpeg");
ImageJPEG($theImage,'', 90);
ImageDestroy($theImage);
}
?>
But I get an error when I run it. It says:
Warning: Supplied argument is not a valid Image resource in C:\Inetpub\wwwroot\image.php on line 27
Line 27 is:
ImageCopyResized($theImage, $tmpImage, 0, 0, 0, 0, $inWidth, $inHeight, ImageSX("media/$inFileName"), ImageSY("media/$inFileName"));
Hope you can help me out.