Back to PhocaGalleryImage class

Method correctSizeWithRate

public static
correctSizeWithRate
(mixed $width, mixed $height, mixed $corWidth = 100, mixed $corHeight = 100)

Method correctSizeWithRate - Source code

public static function correctSizeWithRate($width, $height, $corWidth = 100, $corHeight = 100)
{
    $image['width'] = $corWidth;
    $image['height'] = $corHeight;
    if ($width > $height) {
        if ($width > $corWidth) {
            $image['width'] = $corWidth;
            $rate = $width / $corWidth;
            $image['height'] = $height / $rate;
        } else {
            $image['width'] = $width;
            $image['height'] = $height;
        }
    } else {
        if ($height > $corHeight) {
            $image['height'] = $corHeight;
            $rate = $height / $corHeight;
            $image['width'] = $width / $rate;
        } else {
            $image['width'] = $width;
            $image['height'] = $height;
        }
    }
    return $image;
}