PHP: Resize af billede
Jeg har engang lavet denne funktion til resize af billeder:function reziseImage($src, $dist, $imageType, $maxWidth, $maxHeight) {
list($width, $height) = getimagesize($src);
if ($width>$maxWidth || $height>$maxHeight) {
$scrRatio = $width/$height;
$distRatio = $maxWidth/$maxHeight;
if ($distRatio>$scrRatio) {
$newHeight = $maxHeight;
$newWidth = round($maxHeight*$scrRatio);
} else {
$newHeight = round($maxWidth/$scrRatio);
$newWidth = $maxWidth;
}
} else {
$newWidth=$width;
$newHeight=$height;
}
$thumb = imagecreatetruecolor($newWidth, $newHeight);
if ($imageType == "jpg") {
$source = imagecreatefromjpeg($src);
} elseif ($imageType == "png") {
$source = imagecreatefrompng($src);
} elseif ($imageType == "gif") {
$source = imagecreatefromgif($src);
}
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if ($imageType == "jpg") {
imagejpeg($thumb, "$dist");
} elseif ($imageType == "png") {
imagepng($thumb, "$dist");
} elseif ($imageType == "gif") {
imagegif($thumb, "$dist");
}
}
Jeg har f.eks. dette billede, som jeg kører igennem:
http://www.demaweb.dk/pic01.jpg
Dette resulterer f.eks. i dette thumbnail (maxwidth=150, maxheight=100):
http://www.demaweb.dk/pic02.jpg
Nogen der kan hjælpe mig med at få lavet dette script, sådan billederne ikke bliver så dårlige? Det ser ud som når man ikke trækker i hjørnerne i word f.eks.
