function setCompressionQuality($image_path, $quality)
{
    $backgroundImagick = new \Imagick(realpath($image_path));
    $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();
}