Sets the image sampling factors.
Theoretically, this function allows you to set the sampling factors to be used by the JPEG compressor. In practice though, it does not seem to function particuarly well. I recommend using `Imagick::setImageProperty()` to set 'jpeg:sampling-factor' to one of the standard down-sampling types. e.g. 4:2:0
  • 4:4:4
  • 4:4:1
  • 4:4:0
  • 4:2:2
  • 4:2:0
  • 4:2:1
  • 4:2:0
  • 4:1:1
  • 4:1:0
e.g. Imagick::setImageProperty('jpeg:sampling-factor', '4:2:0');
Original size = 27677
Option 1,1,1 new size 27677
Option 1,1,2 new size 10679
Option 1,2,1 new size 11397
Option 1,2,2 new size 15283
Option 2,1,1 new size 19350
Option 2,1,2 new size 23259
Option 2,2,1 new size 23969
Touch/mouse over to see original View modified in new window.
Image
Sets the image sampling factors.
Theoretically, this function allows you to set the sampling factors to be used by the JPEG compressor. In practice though, it does not seem to function particuarly well. I recommend using `Imagick::setImageProperty()` to set 'jpeg:sampling-factor' to one of the standard down-sampling types. e.g. 4:2:0
  • 4:4:4
  • 4:4:1
  • 4:4:0
  • 4:2:2
  • 4:2:0
  • 4:2:1
  • 4:2:0
  • 4:1:1
  • 4:1:0
e.g. Imagick::setImageProperty('jpeg:sampling-factor', '4:2:0');
Parameters
factorsarray
function setSamplingFactors($imagePath)
{
    $imagePath = "../imagick/images/FineDetail.png";
    $imagick = new \Imagick(realpath($imagePath));
    $imagick->setImageFormat('jpg');
    $imagick->setSamplingFactors(array('2x2', '1x1', '1x1'));

    $compressed = $imagick->getImageBlob();

    
    $reopen = new \Imagick();
    $reopen->readImageBlob($compressed);

    $reopen->resizeImage(
        $reopen->getImageWidth() * 4,
        $reopen->getImageHeight() * 4,
        \Imagick::FILTER_POINT,
        1
    );
    
    header("Content-Type: image/jpg");
    echo $reopen->getImageBlob();
}