private function resizeImagick(Imagick $imagick, Picture $picture)
    {
        if(!$this->resizeSmaller && $this->height > $imagick->getImageHeight() && $this->width > $imagick->getImageWidth())
        {
            return;
        }

        if($this->resizeMode === $this::MODE_CROP)
        {
            $imagick->cropThumbnailImage($this->width, $this->height);
        }
        elseif($this->resizeMode === $this::MODE_FILL)
        {
            $ratioH = $this->height / $imagick->getImageHeight();
            $ratioW = $this->width / $imagick->getImageWidth();

            $width  = max($imagick->getImageWidth() * $ratioH, $imagick->getImageWidth() * $ratioW);
            $height = max($imagick->getImageHeight() * $ratioH, $imagick->getImageHeight() * $ratioW);
            $ratio  = max($width / $imagick->getImageWidth(), $height / $imagick->getImageHeight());

            $imagick->scaleImage(round($imagick->getImageWidth() * $ratio), round($imagick->getImageHeight() * $ratio), TRUE);
        }
        elseif($this->resizeMode === $this::MODE_STRETCH)
        {
            $imagick->scaleImage($this->width, $this->height, FALSE);
        }
        elseif($this->resizeMode === $this::MODE_EXACT)
        {
            $imagick->scaleImage($this->width, $this->height, TRUE);

            $rectangle = $picture->createImagick();
            $rectangle->setFormat('png');
            $rectangle->newImage($this->width, $this->height, new \ImagickPixel($this->color ?: 'transparent'));
            $rectangle->compositeImage($imagick, $imagick->getImageCompose(),

                ($rectangle->getImageWidth() - $imagick->getImageWidth()) / 2,
                ($rectangle->getImageHeight() - $imagick->getImageHeight()) / 2
            );

            $picture->setResource($rectangle);
        }
        else
        {
            $imagick->scaleImage($this->width, $this->height, TRUE);
        }
    }
private function resizeImagick(Imagick $imagick, Picture $picture)
    {
        if(!$this->resizeSmaller && $this->height > $imagick->getImageHeight() && $this->width > $imagick->getImageWidth())
        {
            return;
        }

        if($this->resizeMode === $this::MODE_CROP)
        {
            $imagick->cropThumbnailImage($this->width, $this->height);
        }
        elseif($this->resizeMode === $this::MODE_FILL)
        {
            $ratioH = $this->height / $imagick->getImageHeight();
            $ratioW = $this->width / $imagick->getImageWidth();

            $width  = max($imagick->getImageWidth() * $ratioH, $imagick->getImageWidth() * $ratioW);
            $height = max($imagick->getImageHeight() * $ratioH, $imagick->getImageHeight() * $ratioW);
            $ratio  = max($width / $imagick->getImageWidth(), $height / $imagick->getImageHeight());

            $imagick->scaleImage(round($imagick->getImageWidth() * $ratio), round($imagick->getImageHeight() * $ratio), TRUE);
        }
        elseif($this->resizeMode === $this::MODE_STRETCH)
        {
            $imagick->scaleImage($this->width, $this->height, FALSE);
        }
        elseif($this->resizeMode === $this::MODE_EXACT)
        {
            $imagick->scaleImage($this->width, $this->height, TRUE);

            $rectangle = $picture->createImagick();
            $rectangle->setFormat('png');
            $rectangle->newImage($this->width, $this->height, new \ImagickPixel($this->color ?: 'transparent'));
            $rectangle->compositeImage($imagick, $imagick->getImageCompose(),

                ($rectangle->getImageWidth() - $imagick->getImageWidth()) / 2,
                ($rectangle->getImageHeight() - $imagick->getImageHeight()) / 2
            );

            $picture->setResource($rectangle);
        }
        else
        {
            $imagick->scaleImage($this->width, $this->height, TRUE);
        }
    }
private function resizeImagick ( Imagick $ imagick , Picture $ picture ) { if ( ! $ this -> resizeSmaller && $ this -> height > $ imagick -> getImageHeight ( ) && $ this -> width > $ imagick -> getImageWidth ( ) ) { return ; } if ( $ this -> resizeMode === $ this :: MODE_CROP ) { $ imagick -> cropThumbnailImage ( $ this -> width , $ this -> height ) ; } elseif ( $ this -> resizeMode === $ this :: MODE_FILL ) { $ ratioH = $ this -> height / $ imagick -> getImageHeight ( ) ; $ ratioW = $ this -> width / $ imagick -> getImageWidth ( ) ; $ width = max ( $ imagick -> getImageWidth ( ) * $ ratioH , $ imagick -> getImageWidth ( ) * $ ratioW ) ; $ height = max ( $ imagick -> getImageHeight ( ) * $ ratioH , $ imagick -> getImageHeight ( ) * $ ratioW ) ; $ ratio = max ( $ width / $ imagick -> getImageWidth ( ) , $ height / $ imagick -> getImageHeight ( ) ) ; $ imagick -> scaleImage ( round ( $ imagick -> getImageWidth ( ) * $ ratio ) , round ( $ imagick -> getImageHeight ( ) * $ ratio ) , TRUE ) ; } elseif ( $ this -> resizeMode === $ this :: MODE_STRETCH ) { $ imagick -> scaleImage ( $ this -> width , $ this -> height , FALSE ) ; } elseif ( $ this -> resizeMode === $ this :: MODE_EXACT ) { $ imagick -> scaleImage ( $ this -> width , $ this -> height , TRUE ) ; $ rectangle = $ picture -> createImagick ( ) ; $ rectangle -> setFormat ( 'png' ) ; $ rectangle -> newImage ( $ this -> width , $ this -> height , new \ ImagickPixel ( $ this -> color ? : 'transparent' ) ) ; $ rectangle -> compositeImage ( $ imagick , $ imagick -> getImageCompose ( ) , ( $ rectangle -> getImageWidth ( ) - $ imagick -> getImageWidth ( ) ) / 2 , ( $ rectangle -> getImageHeight ( ) - $ imagick -> getImageHeight ( ) ) / 2 ) ; $ picture -> setResource ( $ rectangle ) ; } else { $ imagick -> scaleImage ( $ this -> width , $ this -> height , TRUE ) ; } }
Resizing an image using Imagick
@param Imagick $imagick
Resizing an image using Imagick