public function resize($width, $height)
    {
        $new = imagecreatetruecolor($width, $height);

        if (empty($new)) {
            throw new UnexpectedValueException('Failed to create an image identifier');
        }

        if ($this->format === 'gif') {

            $transparent_index = imagecolortransparent($this->image);
            $palletsize = imagecolorstotal($this->image);

            if ($transparent_index >= 0 && $transparent_index < $palletsize) {
                $transparent_color = imagecolorsforindex($this->image, $transparent_index);
                $transparent_index = imagecolorallocate($new, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
                imagefill($new, 0, 0, $transparent_index);
                imagecolortransparent($new, $transparent_index);
            }
        } else {
            imagealphablending($new, false);
            imagesavealpha($new, true);
        }

        if (!imagecopyresampled($new, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height)) {
            throw new UnexpectedValueException('Failed to copy and resize part of an image with resampling');
        }

        $this->image = $new;
        $this->width = $width;
        $this->height = $height;

        return $this;
    }
public function resize($width, $height)
    {
        $new = imagecreatetruecolor($width, $height);

        if (empty($new)) {
            throw new UnexpectedValueException('Failed to create an image identifier');
        }

        if ($this->format === 'gif') {

            $transparent_index = imagecolortransparent($this->image);
            $palletsize = imagecolorstotal($this->image);

            if ($transparent_index >= 0 && $transparent_index < $palletsize) {
                $transparent_color = imagecolorsforindex($this->image, $transparent_index);
                $transparent_index = imagecolorallocate($new, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
                imagefill($new, 0, 0, $transparent_index);
                imagecolortransparent($new, $transparent_index);
            }
        } else {
            imagealphablending($new, false);
            imagesavealpha($new, true);
        }

        if (!imagecopyresampled($new, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height)) {
            throw new UnexpectedValueException('Failed to copy and resize part of an image with resampling');
        }

        $this->image = $new;
        $this->width = $width;
        $this->height = $height;

        return $this;
    }
public function resize ( $ width , $ height ) { $ new = imagecreatetruecolor ( $ width , $ height ) ; if ( empty ( $ new ) ) { throw new UnexpectedValueException ( 'Failed to create an image identifier' ) ; } if ( $ this -> format === 'gif' ) { $ transparent_index = imagecolortransparent ( $ this -> image ) ; $ palletsize = imagecolorstotal ( $ this -> image ) ; if ( $ transparent_index >= 0 && $ transparent_index < $ palletsize ) { $ transparent_color = imagecolorsforindex ( $ this -> image , $ transparent_index ) ; $ transparent_index = imagecolorallocate ( $ new , $ transparent_color [ 'red' ] , $ transparent_color [ 'green' ] , $ transparent_color [ 'blue' ] ) ; imagefill ( $ new , 0 , 0 , $ transparent_index ) ; imagecolortransparent ( $ new , $ transparent_index ) ; } } else { imagealphablending ( $ new , false ) ; imagesavealpha ( $ new , true ) ; } if ( ! imagecopyresampled ( $ new , $ this -> image , 0 , 0 , 0 , 0 , $ width , $ height , $ this -> width , $ this -> height ) ) { throw new UnexpectedValueException ( 'Failed to copy and resize part of an image with resampling' ) ; } $ this -> image = $ new ; $ this -> width = $ width ; $ this -> height = $ height ; return $ this ; }
Resize an image to the specified dimensions
@param int $width
@param int $height
@return $this
@throws UnexpectedValueException
Resize an image to the specified dimensions