Scales an image to the desired dimensions with a filter.
Image
Filter type
Width
Height
Blur
Best fit
Crop + zoom
Scales an image to the desired dimensions with a filter.
Parameters
columnsintWidth of the image
rowsintHeight of the image
filterintRefer to the list of filter constants.
blurfloatThe blur factor where > 1 is blurry, < 1 is sharp.
bestfitboolOptional fit parameter.
function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom)
{
    //The blur factor where > 1 is blurry, < 1 is sharp.
    $imagick = new \Imagick(realpath($imagePath));

    $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit);

    $cropWidth = $imagick->getImageWidth();
    $cropHeight = $imagick->getImageHeight();

    if ($cropZoom) {
        $newWidth = $cropWidth / 2;
        $newHeight = $cropHeight / 2;

        $imagick->cropimage(
            $newWidth,
            $newHeight,
            ($cropWidth - $newWidth) / 2,
            ($cropHeight - $newHeight) / 2
        );

        $imagick->scaleimage(
            $imagick->getImageWidth() * 4,
            $imagick->getImageHeight() * 4
        );
    }


    header("Content-Type: image/jpg");
    echo $imagick->getImageBlob();
}