I am creating my first CMS using PHP. for this feature, I want to allow a user to upload an image and PHP will upload the image, then also create a thumbnail of either 100px width or 100px height (depending on if it is portrait or landscape orientation). So far I have only one problem. The GD Function imagecopyresized will create the thumbnail for me, but instead of it being the larger image shrunk to the new size, it creates a cropped version of the larger on in the new size. here is the code please help. it is way over my head.
in the original file (calling from an included function.php)
createThumbnail("uploadedimages", "$image", "uploadedimages/thumbs", 100);
in the function.php page
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $value) {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
if($origWidth > $origHeight) {
$thumbWidth = $value;
$ratio = $thumbWidth / $origWidth;
$thumbHeight = $origHeight * $ratio;
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg));
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
}else{
$thumbHeight = $value;
$ratio = $thumbHeight / $origHeight;
$thumbWidth = $origWidth * $ratio;
$thumbImg = imagecreatetruecolor($thumbHeight, $thumbWidth);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbHeight, $thumbWidth, imagesy($thumbImg), imagesx($thumbImg));
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
}
}