Magento Questions Answered By Magento Experts

 

Sign in | Signup

13 Answers

Change compression in uploaded images

Asked by: Paul Smith 2930 views Questions

After spending days getting my images looking good – I’ve uploaded them to the latest version of Magento only to find them very poorly compressed.

 

Where can I change the compression for this – preferably NO COMPRESSION…

 

Thanks.

 

Paul

13 Answers



  1. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jul 05, 2010

    You need to set quality 100% for image resizing. It can be done by adding of setQuality(100) for all constructions like a construction below
    <?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>
    So it should look like the following after change:
    <?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135)->setQuality(100); ?>

    reply


  2. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 05, 2010

    Thanks for the quick reply I’ll have a look just now.

    Should have mentioned – the big images look ok – the small ones are pretty nasty

    reply


  3. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 05, 2010

    Hmm… I’ve installed ‘magiczoom’ and it seems to have changed ‘new.phtml’

    Is this where you mean I should change the above code?

    Thanks again

    reply


  4. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jul 05, 2010

    I mean all files that display the product images:
    catalog/product/list.phtml
    catalog/product/view/media.phtml
    catalog/product/gallery.phtml
    checkout/cart/item/default.phtml (was $this->getProductThumbnail()->resize(75) should be $this->getProductThumbnail()->setQuality(100)->resize(75))

    And of course the file that you mentioned in your comment.

    reply


  5. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 05, 2010

    Cheers. Strange thing is – even if I upload a pure white image – it still ends up really dirty.

    I’ll change everything and see what happens.

    Ta.

    paul

    reply


  6. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 05, 2010

    Nope cant get rid of the dirty background. I wonder why it would make even a pure white background ‘dirty’…

    Does Magento try and fill in a white background with a 99.6% RGB value?

    http://img291.imageshack.us/img291/8803/magel.png

    reply


    • 0 Votes Thumb up 0 Thumb down 0

      EcommerceDeveloper on Jul 05, 2010

      Magento just changes quality of the image to 90% so white color become more like grey color.

      reply


  7. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jul 05, 2010

    Please present the content of catalog/product/view/media.phtml file. I would like to find out where the problem can be.

    reply


  8. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 05, 2010

    It wouldn’t be so bad if it was a solid colour – it’s just patchy and horrible…

    Here’s the media.phtml file. As I say – magictoolbox changed this file.

    <?php

    /**
    * Magictoolbox product media template for Magento store.
    * Allow use MagicTools on product detailes page.
    * @mail support@magictoolbox.com
    */

    echo '’;

    $tool = & $GLOBALS["magictoolbox"]["magicthumb"];

    if(!defined(‘__MAGICTHUMB_INCLUDED’)) {
    echo $tool->addonsTemplate($this->getSkinUrl(‘images’));
    define(‘__MAGICTHUMB_INCLUDED’,1);
    }

    $_product = $this->getProduct();

    //$allowedPage = $tool->params->checkValue(‘pages’, array(‘Product’, ‘Both’));
    $allowedPage = $tool->params->checkValue(‘use-effect-on-product-page’, ‘Yes’);

    if ($allowedPage && $_product->getImage() != ‘no_selection’ && $_product->getImage()) {
    // we have main image. parce it and print out with Magic Thumb settings.
    $title = $this->htmlEscape($_product->getName());
    $description = $this->htmlEscape($_product->getDescription());
    $shortDescription = $this->htmlEscape($_product->getShortDescription());

    if(!isset($GLOBALS["magictoolbox"]["image_num"])) $GLOBALS["magictoolbox"]["image_num"] = 1;
    $id = ‘magictoolbox’ . $GLOBALS["magictoolbox"]["image_num"]++;

    list($img, $thumb) = magicToolboxResizer($_product, ‘small_image’, $tool->params->getValue(“thumb-size”));
    $img = magicToolboxResizer($_product, ‘image’);

    echo $tool->template(compact(“id”, “title”, “description”, “shortDescription”, “img”, “thumb”));

    } else {
    //product has no main image. print magento default image
    $_img = ‘helper(‘catalog/image’)->init($_product, ‘image’)->resize(265).’” alt=”‘.$this->htmlEscape($_product->getName()).’” />’;
    echo $this->helper(‘catalog/output’)->productAttribute($_product, $_img, ‘image’);
    }

    if (count($this->getGalleryImages()) > 1) {
    // print more images
    ?>

    __(‘More Views’) ?>

    htmlEscape($_product->getName());
    foreach($this->getGalleryImages() as $_image) {
    if($allowedPage) {
    list($img, $medium) = magicToolboxResizer($_product, ‘small_image’, $tool->params->getValue(“thumb-size”), $_image->getFile());
    list($img, $thumb) = magicToolboxResizer($_product, ‘thumbnail’, $tool->params->getValue(“selector-size”), $_image->getFile());
    $img = magicToolboxResizer($_product, ‘image’, null, $_image->getFile());
    if($tool->params->checkValue(‘use-individual-titles’, ‘Yes’)) {
    $title = $this->htmlEscape($_image->getLabel());
    }
    if(empty($title)) {
    $title = $this->htmlEscape($_product->getName());
    }
    $alt = $this->htmlEscape($_image->getLabel());

    $a = $tool->subTemplate(compact(“id”, “img”, “thumb”, “medium”, “title”, “alt”));
    $event = ‘click’;

    $event = $tool->params->getValue(‘swap-image’);

    $a = str_replace(‘<a ', 'params->checkValue(‘ignore-magento-css’, ‘Yes’)) {
    $a = str_replace(“<a ", "<a style=\"width:auto !important; height:auto !important; margin: 0 !important;\" ", $a);
    $a = str_replace("<img ", "<img style=\"width:auto !important; height:auto !important; margin: 0 !important;\" ", $a);
    }
    echo "{$a}”;
    } else {
    ?>
    <a href="#" onclick="popWin('getGalleryUrl($_image) ?>’, ‘gallery’, ‘width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes’); return false;”><img src="helper(‘catalog/image’)->init($this->getProduct(), ‘thumbnail’, $_image->getFile())->resize(56); ?>” alt=”htmlEscape($_image->getLabel()) ?>” title=”htmlEscape($_image->getLabel()) ?>” />

    <?php
    }

    echo '’;
    ?>

    reply


  9. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jul 05, 2010

    Yes, it’s a problem in Magic Zoom module for Magento. Please contact me at admin [at ] ecomdev [dot] com and I’ll help you to solve the problem on your website.

    reply


  10. 0 Votes Thumb up 0 Thumb down 0

    Paul Smith on Jul 06, 2010

    Looks like the problem can be controlled, only negatively, in /lib/Varien/Image/Adapter/Gd2.php

    // set quality param for JPG file type
    if (!is_null($this->quality()) && $this->_fileType == IMAGETYPE_JPEG)
    {
    $functionParameters[] = $this->quality();
    }

    If a value is put in here – 50 for example – $this->quality(50); then all the images as reduced in both size and quality.

    No value in the brackets seems to be the same as 100.

    So – the question is – what do I do now?….

    reply


  11. 0 Votes Thumb up 0 Thumb down 0

    EcommerceDeveloper on Jul 06, 2010

    I think i found the problem, i’ve downloaded magic tool box and find out that they don’t specify PNG quality when doing out put of PNG image. If you want to fix compression of png files you should open /app/etc/magictoolbox/core/magictoolbox.makethumb.class.php file and find the following line:
    case "png": imagepng($this->data, $this->thumb); touch($this->thumb, @filemtime($this->img)); break;

    and replace it with this (sets compression to NO COMMPRESSION):
    case "png": imagepng($this->data, $this->thumb, 0); touch($this->thumb, @filemtime($this->img)); break;

    As for question about Magento core functionality with resizing, it’s easy to specify image quality in template by adding setQuality() in image initialization. By default Magento makes JPG files with 90% of original quality. But your problem is not in Magento core functionality, because Magic Tool box, that you’ve installed doesn’t use Magento image resizer, it uses its own functionality.

    If you have any problems, feel free to contact me.

    reply


  12. 0 Votes Thumb up 0 Thumb down 0

    David L on Dec 31, 2010

    Hello guys,

    just wondering about using just the original size. I have modified both Gd2.php and Mage/Media/File/Image.php quality to 100, but I can still notice loss of color in cached one.

    Original image uploaded to magento in /media file is much more vibrant color than the one in /media/cache file that magento creates.

    Is there any way to just cache original picture without losing any quality? or maybe not going through image library at all?

    reply

Answer Question

Please use <code> </code> tags to display code.