Magento Questions Answered By Magento Experts

 

Welcome Guest. Sign in or Signup

13 Answers

Change compression in uploaded images

Asked by: 4606 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. EcommerceDeveloper on Jul 05, 2010 Reply

    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); ?>

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  2. Paul Smith on Jul 05, 2010 Reply

    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

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  3. Paul Smith on Jul 05, 2010 Reply

    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

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  4. EcommerceDeveloper on Jul 05, 2010 Reply

    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.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  5. Paul Smith on Jul 05, 2010 Reply

    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

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  6. Paul Smith on Jul 05, 2010 Reply

    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

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



    • EcommerceDeveloper on Jul 05, 2010 Reply

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

      0 Votes Thumb up 0 Votes Thumb down 0 Votes



  7. EcommerceDeveloper on Jul 05, 2010 Reply

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

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  8. Paul Smith on Jul 05, 2010 Reply

    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 '’;
    ?>

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  9. EcommerceDeveloper on Jul 05, 2010 Reply

    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.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  10. Paul Smith on Jul 06, 2010 Reply

    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?….

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  11. EcommerceDeveloper on Jul 06, 2010 Reply

    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.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  12. David L on Dec 31, 2010 Reply

    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?

    0 Votes Thumb up 0 Votes Thumb down 0 Votes


Answer Question