Images compressed with Imagick fail Pagespeed test

Asked

Viewed 88 times

0

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

Even with that code, PageSpeed of Google continues to accuse that images need reduction.

$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();
  • But then you have to take into account if it is considering the actual compression or if the photo has been reduced with css or with attributes like width and height, making the original size unnecessary, which would be worth (measuring the cost benefit) generating a version with better size, summarizing "the problem may be partially in HTML". But I have no way of knowing without having details, especially the details reported by the pagespeed itself, because you may have misinterpreted what they say in the "log"

  • This is the result of pagespeed where it points out the problem: https://developers.google.com/speed/pagespeed/insights/? hl=en-br&url=https%3A%2F%2Fwww.infochat.com.br%2Fbusca%2Fporto-alegre%2Frs%2Ftodos%2Fjose

  • Dear Diego, that’s exactly what I said, I formulated the answer.

1 answer

2


The original image is 628x480, meaning the image speaks to compression and "resizing":

The compaction and resizing of https://www.infochat.com.br/...1809042141221536108082.0203631465967.jpg could save 27.9 Kib (reduction of 93%).

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

  • I ended up resizing the image and it worked, but some images still need compression, would you have another parameter of Imagick to add? https://developers.google.com/speed/pagespeed/insights/? hl=en-br&url=https%3A%2F%2Fwww.infochat.com.br%2Fbusca%2Fporto-alegre%2Frs%2Ftodos%2Flemos&tab=desktop

  • @Diegovieira is that Imagick as well as GD probably add some "thingies", Alliis the compression of 15% I found too much exaggerated, the most I could with a tool that I have own for this under its current image was 8%, sometimes pagespeed is a little exaggerated (I think, personally), but it may be some layer that is independent of compression, it may be something of the very Imagick.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.