Hello all.
I'm new to working with functions and I'm trying to use one I found which is supposed to take a full size image, create a thumbnail from it, and save the thumbnail. But when I execute the code I get these errors:
Warning: Missing argument 1 for savethumbnail() in /home/usr21111/public_html/tests/image.php on line 7
Warning: Missing argument 2 for savethumbnail() in /home/usr21111/public_html/tests/image.php on line 7
Warning: Missing argument 3 for savethumbnail() in /home/usr21111/public_html/tests/image.php on line 7
Warning: Missing argument 4 for savethumbnail() in /home/usr21111/public_html/tests/image.php on line 7
Warning: Missing argument 5 for savethumbnail() in /home/usr21111/public_html/tests/image.php on line 7
Do you see what I'm doing wrong? Am I calling the function wrong or something?
<?php
function saveThumbnail($saveToDir, $imagePath, $imageName, $max_x, $max_y) {
preg_match("'^(.*)\.(gif|jpe?g|png)$'i", $imageName, $ext);
switch (strtolower($ext[2])) {
case 'jpg' :
case 'jpeg': $im = imagecreatefromjpeg ($imagePath);
break;
case 'gif' : $im = imagecreatefromgif ($imagePath);
break;
case 'png' : $im = imagecreatefrompng ($imagePath);
break;
default : $stop = true;
break;
}
if (!isset($stop)) {
$x = imagesx($im);
$y = imagesy($im);
if (($max_x/$max_y) < ($x/$y)) {
$save = imagecreatetruecolor($x/($x/$max_x), $y/($x/$max_x));
}
else {
$save = imagecreatetruecolor($x/($y/$max_y), $y/($y/$max_y));
}
imagecopyresized($save, $im, 0, 0, 0, 0, imagesx($save), imagesy($save), $x, $y);
imagegif($save, "{$saveToDir}{$ext[1]}.gif");
imagedestroy($im);
imagedestroy($save);
}
}
?>
<?php
$saveToDir = "/tests/thumbs";
$imagePath = "/tests/images";
$imageName = "picture.jpg";
$max_x = "100";
$max_y = "100";
saveThumbnail();
?>
Thank you as always!
Peter