yii\imagine\BaseImage::getBox PHP Méthode

getBox() protected static méthode

If one of the dimensions is set to null, another one is calculated automatically based on width to height ratio of original image box. If both of the dimensions are set then new dimensions are calculated so that image keeps aspect ratio. You can set $keepAspectRatio to false if you want to force fixed width and height.
Since: 2.1.1
protected static getBox ( Imagine\Image\BoxInterface $sourceBox, integer $width, integer $height, boolean $keepAspectRatio = true ) : Imagine\Image\BoxInterface
$sourceBox Imagine\Image\BoxInterface original image box
$width integer new image width
$height integer new image height
$keepAspectRatio boolean should we keep aspect ratio even if both with and height are set
Résultat Imagine\Image\BoxInterface new image box
    protected static function getBox(BoxInterface $sourceBox, $width, $height, $keepAspectRatio = true)
    {
        if ($width === null && $height === null) {
            throw new InvalidParamException('Width and height cannot be null at same time.');
        }
        $ratio = $sourceBox->getWidth() / $sourceBox->getHeight();
        if ($keepAspectRatio === false) {
            if ($height === null) {
                $height = ceil($width / $ratio);
            } elseif ($width === null) {
                $width = ceil($height * $ratio);
            }
        } else {
            if ($height === null) {
                $height = ceil($width / $ratio);
            } elseif ($width === null) {
                $width = ceil($height * $ratio);
            } elseif ($width / $height > $ratio) {
                $width = $height * $ratio;
            } else {
                $height = $width / $ratio;
            }
        }
        return new Box($width, $height);
    }