1. Home
  2. Docs
  3. WebP Compression for OpenCart
  4. Image Quality
  5. Improving Image Quality

Improving Image Quality

  1. Requires skills to edit files in the server.
  2. Improving image quality increases the size of the image as well.

This extension works on the images that are already compressed by the default OpenCart image library for JPEG images and are saved in image/cache/ folder. For improving the image quality of these JPEG images, do the following changes

  1. Open file system/library/image.php
  2. Look for the line
    public function save($file, $quality = 90) {
  3. Change the value of $quality to > 90, for example
    public function save($file, $quality = 100) { 

The above steps will improve the overall image quality of the images generated by the OpenCart. Please note this is applicable only for JPEG images and not for PNG or GIF images. Now generate the fresh webp images. The webp compression algorithm of this extension chooses the best compression quality by automatically. Check the quality and if you want to further improve the image quality, do the following.

  1. Open file admin/controller/extension/hbseo/hb_webp.php
  2. Look for the code $options = [];
  3. Replace it with the following and adjust the quality value
$options = [
    'png' => [
        'encoding' => 'lossy',   /* Try both lossy and lossless and pick smallest */
        'near-lossless' => 60,   /* The level of near-lossless image preprocessing (when trying lossless) */
        'quality' => 85,         /* Quality when trying lossy. It is set high because pngs is often selected to ensure high quality */
    ],
    'jpeg' => [
        'encoding' => 'auto',     /* If you are worried about the longer conversion time, you could set it to "lossy" instead (lossy will often be smaller than lossless for jpegs) */
        'quality' => 90,      /* Set to same as jpeg (requires imagick or gmagick extension, not necessarily compiled with webp) */
        'max-quality' => 80,      /* Only relevant if quality is set to "auto" */
        'default-quality' => 75,  /* Fallback quality if quality detection isnt working */
    ]
];


Test it by clearing the image cache folder and regenerate webp images.

If you are satisfied with the code do the same in the ocmod XML file of this extension.

Was this article helpful to you? Yes No