<?php
function scale($img,$maxwidth,$maxheight) {
$imgwidth = $imginfo[0];
$imgheight = $imginfo[1];
if ($imgwidth > $maxwidth) {
$ration = $maxwidth/$imgwidth;
$newwidth = round($imgwidth*$ration); $newheight = round($imgheight*$ration); if ($newheight > $maxheight) {
$ration = $maxheight/$newheight;
$newwidth = round($newwidth*$ration); $newheight = round($newheight*$ration); return array("image" => $img, "width" => $newwidth, "height" => $newheight); } else {
return array("image" => $img, "width" => $newwidth, "height" => $newheight); }
} else if ($imgheight > $maxheight) {
$ration = $maxheight/$imgheight;
$newwidth = round($imgwidth*$ration); $newheight = round($imgheight*$ration); if ($newwidth > $maxwidth) {
$ration = $maxwidth/$newwidth;
$newwidth = round($newwidth*$ration); $newheight = round($newheight*$ration); return array("image" => $img, "width" => $newwidth, "height" => $newheight); } else {
return array("image" => $img, "width" => $newwidth, "height" => $newheight); }
} else {
return array("image" => $img, "width" => $imgwidth, "height" => $imgheight); }
}
?>
$maxwidth i $maxheight i po sprawie