src/Image.php
public function scale_and_crop($width, $height)
    {
        if ($width === null) {
            throw new \LogicException('"width" must not be null for "scale_and_crop"');
        }

        if ($height === null) {
            throw new \LogicException('"height" must not be null for "scale_and_crop"');
        }

        $scale = max($width / $this->getWidth(), $height / $this->getHeight());
        $w = ceil($this->getWidth() * $scale);
        $h = ceil($this->getHeight() * $scale);
        $x = ($w - $width) / 2;
        $y = ($h - $height) / 2;

        $this->resize($w, $h);
        $this->crop($x, $y, $width, $height);
    }
public function scale_and_crop($width, $height)
    {
        if ($width === null) {
            throw new \LogicException('"width" must not be null for "scale_and_crop"');
        }

        if ($height === null) {
            throw new \LogicException('"height" must not be null for "scale_and_crop"');
        }

        $scale = max($width / $this->getWidth(), $height / $this->getHeight());
        $w = ceil($this->getWidth() * $scale);
        $h = ceil($this->getHeight() * $scale);
        $x = ($w - $width) / 2;
        $y = ($h - $height) / 2;

        $this->resize($w, $h);
        $this->crop($x, $y, $width, $height);
    }
public function scale_and_crop ( $ width , $ height ) { if ( $ width === null ) { throw new \ LogicException ( '"width" must not be null for "scale_and_crop"' ) ; } if ( $ height === null ) { throw new \ LogicException ( '"height" must not be null for "scale_and_crop"' ) ; } $ scale = max ( $ width / $ this -> getWidth ( ) , $ height / $ this -> getHeight ( ) ) ; $ w = ceil ( $ this -> getWidth ( ) * $ scale ) ; $ h = ceil ( $ this -> getHeight ( ) * $ scale ) ; $ x = ( $ w - $ width ) / 2 ; $ y = ( $ h - $ height ) / 2 ; $ this -> resize ( $ w , $ h ) ; $ this -> crop ( $ x , $ y , $ width , $ height ) ; }
Scales an image to the exact width and height given.

This function achieves the target aspect ratio by cropping the original image
equally on both sides, or equally on the top and bottom. This function is
useful to create uniform sized avatars from larger images.

The resulting image always has the exact target dimensions.

@param int $width The target width, in pixels.
@param int $height The target height, in pixels.

@throws \LogicException if the parameters are wrong

@see resize()
@see crop()
Scales an image to the exact width and height given .