Sets the object's default compression quality.
Touch/mouse over to see original View modified in new window.
Image
Quality
Sets the object's default compression quality.
Parameters
qualityint
function setCompressionQuality($imagePath, $quality)
{
    $backgroundImagick = new \Imagick(realpath($imagePath));
    $imagick = new \Imagick();
    $imagick->setCompressionQuality($quality);
    $imagick->newPseudoImage(
        $backgroundImagick->getImageWidth(),
        $backgroundImagick->getImageHeight(),
        'canvas:white'
    );
    
    $imagick->setFormat("jpg");
    header("Content-Type: image/jpg");
    echo $backgroundImagick->getImageBlob();
}