Proportional image sizing

Proportional image sizing

// First make sure the height is below $maxHeight
if($newHeight > $maxHeight) {
$newHeight = $maxHeight;
$newWidth = round($cWidth / ($cHeight / $newHeight));
}

// Afterwards check that the width is below $maxWidth
if($newWidth > $maxWidth) {
$newHeight = round($newHeight / ($newWidth / $maxWidth));
$newWidth = $maxWidth;
}

Here’s my PHP script you can download as an example (zipped).

Leave a Reply