When you upload an product image, PrestaShop doesn't just move it to the /img/p/ folder, it compresses the image by using the "JPEG compression" value you sent on the "Bo>Images" page as the "original" image, and then generate thumbnails based on the already compressed "original" image, the "original" image is not original image any more, it has lost a lot valuable details. Which is not that wrong, in most cases, but it would cause a big trouble when you want to optimize your images. Because of you can generated quality good, clear, sharp and detailed images based on already compressed "original" images.
The same case also happens when you upload banner images, logo, etc, that's why people complain their logos are blurry than the original ones, we care the logo a lot that why we can tell if a logo is clear or blur, actually what happens to the logo also happens to product images, which means all product images look somehow blurry.
Unable to show clear and detailed images.
The default value of "JPEG compression" is 90, the "original" images has already lost about 10% details, when you want to optimized images by using Imagemagick or other similar tools, those 10% details can't come back anymore.
The worst case
If you set the "JPEG compression" to 70, product images will be saved 70 in quality, but one day you want to set back to the recommended 90, that's not possible, an image which is 70 in quality can't be compressed back to 90 in quality. Here are some comparisons, beside use our eyes to tell the differences, we also use SSIM which is the best measurement of image quality, Google uses SSIM a lot on their documentations, more info about SSIM
The last one is forced from 70 in quality to 90 in quality, logically it's impossible to set quality from 70 back to 90, because of 70 in quality means the images only contains about 70% details of the original image. In this case, those 20% more details are created by computer, they are not real. Comparing the last image and the second one, the last one's SSIM is also 0.002 lower, our eyes are capable to us, the second one is more good in quality.
Fix it.
NOTE: If you are using our Imagemagick module or WebP module, then not need to apply the fix, because those two modules have the fix included.
Add this code to the resize function in the \classes\ImageManager.php file.
1 2 3 | if (preg_match('/\/img\/(p|c|m|s|st)\/(\d+\/)*\d+\.(jpg|jpeg|png|gif)$/Us', $destinationFile)) { return @copy($sourceFile, $destinationFile); } |
It's commended for everyone to apply the fix even if you currently have no plans of doing image optimization, to apply the fix is just in case one day you change your mind, till then you can just install a module to optimize your images, not need to re-upload all images.
Hello!
Thanks for the great thought!
This method applicable to prestashop 1.6 or prestashop 1.7 or both?
Hi,
The fix is for Prestashop 1.6 and 1.7.
Best regards.