Images compressed with Imagick do not pass the PageSpeed test

0

What parameters can I add to Imagick to improve image compression?

Even with this code, PageSpeed Google continues to accuse images need to be reduced.

$image = new \Imagick($request->img->path());
$image->setImageFormat('jpg');
$fileName = date('YmdHis') . microtime(true) . rand(111111111, 999999999) . '.' . $image->getImageFormat();
$image->setImageCompressionQuality(70);
$image->stripImage();
$image->setSamplingFactors(array('2x2', '1x1', '1x1'));
$image->setInterlaceScheme(\Imagick::INTERLACE_JPEG);
$image->setColorspace(\Imagick::COLORSPACE_SRGB);
$image->writeImage($path . '/' . $fileName);
$image->destroy();
    
asked by anonymous 05.09.2018 / 04:17

1 answer

2

The original image has 628x480, ie the image speaks compression and "resizing":

  

Compressing and resizing link ... could save 27.9 KiB (93% reduction).

Just look at the page, with css width: 100% the image was 76 wide, meaning you're pasting with <img> an image that is 86% larger than needed (I'm not counting compression) in Desktop. What pagespeed-insights is to create an image with the approximate size it will use, or perhaps more than one, one with the original size and one with the reduced size.

    
05.09.2018 / 05:28