Hello, I've been searching for a tutorial to create thumbnails for a while and finally found one that works for me. It's doing everything it's suppose to except one thing.
I created a test image 600px wide, 700px high, so to get 300px width it would need to half that, as well as the 700px height. It's resizing the width to half the size (300px) except instead of halfing the height to 350px, it doubles it to 1400px, which obviously causes the image to come out very wrong.
Here's the code I'm using:
[code=php]
function createThumbnail ($imageDirector y, $imageName, $thumbDirectory , $thumbWidth)
{
$srcImg = imagecreatefrom jpeg("$imageDir ectory/$imageName");
$origWidth = imagesx($srcImg );
$origHeight = imagesy($srcImg );
$ratio = $origWidth / $thumbWidth;
$thumbHeight = $origHeight * $ratio;
$thumbImg = imagecreate($th umbWidth, $thumbHeight);
imagecopyresize d($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbI mg), imagesy($thumbI mg));
imagejpeg($thum bImg, "$thumbDirector y/$imageName");
}
createThumbnail ("uploads/examples", "$newname", "uploads/examples/thumbnails", 300);
[/code]
Thanks,
Jeigh.
I created a test image 600px wide, 700px high, so to get 300px width it would need to half that, as well as the 700px height. It's resizing the width to half the size (300px) except instead of halfing the height to 350px, it doubles it to 1400px, which obviously causes the image to come out very wrong.
Here's the code I'm using:
[code=php]
function createThumbnail ($imageDirector y, $imageName, $thumbDirectory , $thumbWidth)
{
$srcImg = imagecreatefrom jpeg("$imageDir ectory/$imageName");
$origWidth = imagesx($srcImg );
$origHeight = imagesy($srcImg );
$ratio = $origWidth / $thumbWidth;
$thumbHeight = $origHeight * $ratio;
$thumbImg = imagecreate($th umbWidth, $thumbHeight);
imagecopyresize d($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbI mg), imagesy($thumbI mg));
imagejpeg($thum bImg, "$thumbDirector y/$imageName");
}
createThumbnail ("uploads/examples", "$newname", "uploads/examples/thumbnails", 300);
[/code]
Thanks,
Jeigh.
Comment