Sulu\Bundle\MediaBundle\Media\ImageConverter\Scaler\Scaler::getHeightWidth PHP Method

getHeightWidth() private method

Gets the height and width of the resulting image, according to the given parameters.
private getHeightWidth ( $x, $y, $retina, $forceRatio, $size, $mode ) : array
$x
$y
$retina
$forceRatio
$size
$mode
return array
    private function getHeightWidth($x, $y, $retina, $forceRatio, $size, $mode)
    {
        $newWidth = $x;
        $newHeight = $y;
        // retina x2
        if ($retina) {
            $newWidth = $x * 2;
            $newHeight = $y * 2;
        }
        // calculate height when not set
        if (!$newHeight) {
            $newHeight = $size->getHeight() / $size->getWidth() * $newWidth;
        }
        // calculate width when not set
        if (!$newWidth) {
            $newWidth = $size->getWidth() / $size->getHeight() * $newHeight;
        }
        // if image is smaller keep ratio
        // e.g. when a square image is requested (200x200) and the original image is smaller (150x100)
        //      it still returns a squared image (100x100)
        if ($mode === ImageInterface::THUMBNAIL_OUTBOUND && $forceRatio) {
            if ($newWidth > $size->getWidth()) {
                list($newHeight, $newWidth) = $this->getSizeInSameRatio($newHeight, $newWidth, $size->getWidth());
            }
            if ($newHeight > $size->getHeight()) {
                list($newWidth, $newHeight) = $this->getSizeInSameRatio($newWidth, $newHeight, $size->getHeight());
            }
        }
        return [$newWidth, $newHeight];
    }