protected function calculateSize(array $params, array $imageSize) {
        $maxWidth = !empty($params['width']) ? (int) $params['width'] : 0;
        $maxHeight = !empty($params['height']) ? (int) $params['height'] : 0;

        $sourceWidth  = $imageSize['width'];
        $sourceHeight = $imageSize['height'];

        $width  = $maxWidth  ?: $sourceWidth;
        $height = $maxHeight ?: $sourceHeight;

        // Figure out original ratio
        $ratio = $sourceWidth / $sourceHeight;

        if (($width / $height) > $ratio) {
            $width  = round($height * $ratio);
        } else {
            $height = round($width / $ratio);
        }

        // Is the original image smaller than the specified parameters?
        if ($sourceWidth <= $width && $sourceHeight <= $height) {
            // Original image is smaller than the max-parameters, don't transform
            return;
        }

        return ['width' => $width, 'height' => $height];
    }