I installed a simple gallery script into my WordPress, and everything works fine. I just want to change the way the ImageMagick thumbs the full-size pics.
In the script you can change the thumb size. Say I set it to 110x170 and the full-size pic is 600x200 - when you load it up, it thumbs the image to fit the height, not the width.
I want it to fit the width.
Make sense?
Code:
generateImg($_GET['file'], $_GET['thumb']);
function generateImg($img, $thumb) {
global $gallery_root, $pictwidth, $pictheight, $thumbwidth, $thumbheight;
if($thumb) {
$height = $thumbheight;
$width = $thumbwidth;
} else {
$height = $pictheight;
$width = $pictwidth;
}
$img = $gallery_root.$img;
$path = pathinfo($img);
switch(strtolower($path["extension"])){
case "jpeg":
case "jpg":
Header("Content-type: image/jpeg");
$img=imagecreatefromjpeg($img);
break;
case "gif":
Header("Content-type: image/gif");
$img=imagecreatefromgif($img);
break;
case "png":
Header("Content-type: image/png");
$img=imagecreatefrompng($img);
break;
default:
break;
}
$xratio = $width/(imagesx($img));
$yratio = $height/(imagesy($img));
if($xratio < 1 || $yratio < 1) {
if($xratio < $yratio)
$resized = imagecreatetruecolor($width,floor(imagesy($img)*$xratio));
else
$resized = imagecreatetruecolor(floor(imagesx($img)*$yratio), $height);
imagecopyresampled($resized, $img, 0, 0, 0, 0, imagesx($resized)+1,imagesy($resized)+1,imagesx($img),imagesy($img));
imagejpeg($resized);
imagedestroy($resized);
}
else
{
imagejpeg($img);
}
imagedestroy($img);
}