<?php
function setCompressionQuality($imagePath, $quality) {
$backgroundImagick = new \Imagick(realpath($imagePath));
$imagick = new \Imagick();
$imagick->setCompressionQuality($quality);
$imagick->newPseudoImage(
$backgroundImagick->getImageWidth(),
$backgroundImagick->getImageHeight(),
'canvas:white'
);
$imagick->compositeImage(
$backgroundImagick,
\Imagick::COMPOSITE_ATOP,
0,
0
);
$imagick->setFormat("jpg");
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
?>