src/Modifiers/ImageModifier.php
public function resize( $width = null, $height = null )
    {
        // Get the source width and height
        $sourceWidth = imagesx( $this->image );
        $sourceHeight = imagesy( $this->image );

        // Check if any of the width and height is null, and set it to the $source size
        // $width = $width ?: $sourceWidth;
        // $height = $height ?: $sourceHeight;
        $sourceAspectRatio = $sourceWidth / $sourceHeight;

        if ( !$width && !$height ) {
            $width = $sourceWidth;
            $height = $sourceHeight;
        }
        else if ( ! $width ) {
            $width = $height * $sourceAspectRatio;
        }
        else {
            $height = $width / $sourceAspectRatio;
        }

        $maxCanvasWidth = $width;
        $maxCanvasHeight = $height;

        $thumbnailAspectRatio = $maxCanvasWidth / $maxCanvasHeight;

        // Create canvas for the new image
        $canvas = $this->createCanvas( $width, $height );

        // Do the resizing of the image
        imagecopyresampled($canvas, $this->image, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight);

        // Replace the current image
        $this->replace( $canvas );

        // Return this for linking
        return $this;
    }
public function resize( $width = null, $height = null )
    {
        // Get the source width and height
        $sourceWidth = imagesx( $this->image );
        $sourceHeight = imagesy( $this->image );

        // Check if any of the width and height is null, and set it to the $source size
        // $width = $width ?: $sourceWidth;
        // $height = $height ?: $sourceHeight;
        $sourceAspectRatio = $sourceWidth / $sourceHeight;

        if ( !$width && !$height ) {
            $width = $sourceWidth;
            $height = $sourceHeight;
        }
        else if ( ! $width ) {
            $width = $height * $sourceAspectRatio;
        }
        else {
            $height = $width / $sourceAspectRatio;
        }

        $maxCanvasWidth = $width;
        $maxCanvasHeight = $height;

        $thumbnailAspectRatio = $maxCanvasWidth / $maxCanvasHeight;

        // Create canvas for the new image
        $canvas = $this->createCanvas( $width, $height );

        // Do the resizing of the image
        imagecopyresampled($canvas, $this->image, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight);

        // Replace the current image
        $this->replace( $canvas );

        // Return this for linking
        return $this;
    }
public function resize ( $ width = null , $ height = null ) { // Get the source width and height $ sourceWidth = imagesx ( $ this -> image ) ; $ sourceHeight = imagesy ( $ this -> image ) ; // Check if any of the width and height is null, and set it to the $source size // $width = $width ?: $sourceWidth; // $height = $height ?: $sourceHeight; $ sourceAspectRatio = $ sourceWidth / $ sourceHeight ; if ( ! $ width && ! $ height ) { $ width = $ sourceWidth ; $ height = $ sourceHeight ; } else if ( ! $ width ) { $ width = $ height * $ sourceAspectRatio ; } else { $ height = $ width / $ sourceAspectRatio ; } $ maxCanvasWidth = $ width ; $ maxCanvasHeight = $ height ; $ thumbnailAspectRatio = $ maxCanvasWidth / $ maxCanvasHeight ; // Create canvas for the new image $ canvas = $ this -> createCanvas ( $ width , $ height ) ; // Do the resizing of the image imagecopyresampled ( $ canvas , $ this -> image , 0 , 0 , 0 , 0 , $ width , $ height , $ sourceWidth , $ sourceHeight ) ; // Replace the current image $ this -> replace ( $ canvas ) ; // Return this for linking return $ this ; }
Resize the GD Image

@return $this
Resize the GD Image