Magento Forum

   
Image cache compression ? 
 
PitchOu
Member
 
Total Posts:  39
Joined:  2008-02-04
Villeneuve d'Ascq, France
 

Hi all magento team and users !

Is there a compression level set somewhere for cached images ?

The quality of all my cached images is far less worse thant the original ones ! Please see the 2 images attached for comparison :

small1.jpg --> /shop/media/catalog/product/s/m/small.jpg (not cached)

small2.jpg --> /shop/media/catalog/product/cache/1/small_image//135x135/s/m/small.jpg (cached)

Can I set or change this compression factor ?

Thanks for your help !

Image Attachments
small2.jpgsmall1.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
PitchOu
Member
 
Total Posts:  39
Joined:  2008-02-04
Villeneuve d'Ascq, France
 

Finally I modified lib/Varien/Image/Adapter/Gd2.php

The jpeg images are generated using the php imagejpeg function using the default quality, which is 75% (= sometimes not enough to get a good quality).

So I hardcoded a quality that suits my needs, thus :

- I upload images in jpeg 100% in the product creation process
- they are processed by the system (resizing, watermark if any, ...)
- they are saved in the media / cache folders ... using imagejpeg with the new quality parameter

and I got nice pictures now !

Do do it right I should have had a “jpeg quality” parameter in the admin but I don’t have the time now ... I have a shop to open wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_dimsum
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-28
 

Be great if you can go a bit extensive to let us know how about you managed to modify the compression quality. :D

 
Magento Community Magento Community
Magento Community
Magento Community
 
FOOMAN
Guru
 
Avatar
Total Posts:  669
Joined:  2007-12-13
Auckland, New Zealand
 

Hi Dimsum,

You can up the quality of the thumbnails generated in this file

/lib/Varien/Image/Adapter/Gd2.php

Look for:

case IMAGETYPE_JPEG:
                
imagejpeg($this->_imageHandler$fileName);
                break;

and change it to

case IMAGETYPE_JPEG:
                
imagejpeg($this->_imageHandler$fileName100);
                break;

More info on imagejpeg and related image handlers can be found here

 
Magento Community Magento Community
Magento Community
Magento Community
 
Oxa Koba
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2008-04-15
Oregon, United States
 

Is it possible to disable this feature completely.

I prefer to compress my image on a image by image basis.

And another question, is there a easy way to switch to a different “viewer” for images. Something more like the slide-style viewer on The Climbing Shop.

 
Magento Community Magento Community
Magento Community
Magento Community
 
aDy
Jr. Member
 
Avatar
Total Posts:  25
Joined:  2008-05-09
France
 

Hi !

I think is a very good idea for the next releases of Magento, we can disable easely the jpg compression, because when i save the pictures with photoshop they are already optimized !

Sorry for my english, and thanks for your reading wink

Amically,
Ady

 
Magento Community Magento Community
Magento Community
Magento Community
 
norbolig
Guru
 
Total Posts:  328
Joined:  2008-03-15
 

@FOOMAN: Excellent! This solved my problem with poor quality images in my store view.

The inbuilt compression worked well on bigger images, but I got problems on small images, especially that I had to resize before I uploaded.
After this fix, I can have Photoshop take care of the image optimizing.

Thanks a lot.

 
Magento Community Magento Community
Magento Community
Magento Community
 
00christian00
Sr. Member
 
Total Posts:  87
Joined:  2008-05-02
 

In version 1.1 the code has changed.
To up the quality change the line 68

call_user_func($this->_getCallback('output'), $this->_imageHandler$fileName);

to

if (IMAGETYPE_JPEG === $this->_fileType)call_user_func($this->_getCallback('output'), $this->_imageHandler$fileName,90);
        else 
        
call_user_func($this->_getCallback('output'), $this->_imageHandler$fileName);

90 is my quality,change to your preference.Remember to clear the image cache to test.

 
Magento Community Magento Community
Magento Community
Magento Community
 
doctorlogos
Sr. Member
 
Avatar
Total Posts:  178
Joined:  2008-05-06
 

I also think that the compression rate must be a configurable option from the admin, so I don´t have to change the code.

I optimize all the images from Fireworks, so it´s already compressed.

I hope for the next realise.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bozmac
Jr. Member
 
Total Posts:  18
Joined:  2008-06-17
 

Line 174 of Mage_Media_Model_File_Image

$result = imagejpeg($object->getTmpImage(), $object->getFilePath(true), 80);
change to 100 for no compression but big file sizes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mayerwin
Sr. Member
 
Avatar
Total Posts:  182
Joined:  2008-01-15
France
 

Solution here: http://www.magentocommerce.com/boards/viewthread/6158/P15/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top