4

I have created versions of my product images that look exactly how I want them to when viewed on the web. They are also at a size (weight) that I find acceptable. The problem is, once I upload to magento, some automatic compression kicks in and all images go ugly.

How do I disable all image compression (which I assume is the only thing making them ugly)? I want it disabled on the product page, the catalog page, the cart and anywhere else my product images might show up. I'm happy with the automatic resizing, just not the compression.

Can only find really old and conflicting answers to this so I would love to hear how you pros feel about this today with magento 1.9.

2

This is an issue caused by Gd2 library, there is an ImageMagic adapter that can help:

https://github.com/magento-hackathon/Perfect_Watermarks

If you want you can also try to fix Gd2:

Just copy lib/Varien/Image/Adapter/Gd2.php to app/code/local/Varien/Image/Adapter/Gd2.php

And then find the following code inside the resize function:

// resample source image and copy it into new frame
imagecopyresampled(
    $newImage,
    $this->_imageHandler,
    $dstX, $dstY,
    $srcX, $srcY,
    $dstWidth, $dstHeight,
    $this->_imageSrcWidth, $this->_imageSrcHeight
);

And add this code after:

// Clean noise on white background images
if ($isTrueColor) {
    $colorWhite = imagecolorallocate($newImage,255,255,255);
    $processHeight = $dstHeight+$dstY;
    $processWidth = $dstWidth+$dstX;
    //Travel y axis
    for($y=$dstY; $y<($processHeight); ++$y){
        // Travel x axis
        for($x=$dstX; $x<($processWidth); ++$x){
            // Change pixel color
            $colorat=imagecolorat($newImage, $x, $y);
            $r = ($colorat >> 16) & 0xFF;
            $g = ($colorat >> 8) & 0xFF;
            $b = $colorat & 0xFF;
            if(($r==253 && $g == 253 && $b ==253) || ($r==254 && $g == 254 && $b ==254)) {
                imagesetpixel($newImage, $x, $y, $colorWhite);
            }
        }
    }
}

The credit goes to: https://stackoverflow.com/questions/8384678/magento-resize-image-quality

  • Thanks! So this handles a colour issue? Is this separate from the compression issue as mentioned in the answer by @fiasco-labs or does this code take care of the compression as well? – Klistrian Jun 3 '15 at 11:37
  • 1
    This is an answer to a wrong question. 1) it addresses a very specific issue, gray lines/dots on pure white background, as the referenced question states; 2) processing pixels in PHP, seriously? Under production load? There should be a hardware-accelerated GD2 threshold filter for that. – Victor Sergienko Mar 16 '16 at 13:29
0

If it's just the compression that's the issue, change the Image load calls in your templates to setQuality(100)

For example, Small Image load is:

<php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); >

Change to:

<php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135)->setQuality(100); >

Then empty image cache so Magento recreates the resized images.

  • Thanks! So the Gd2 issue as mentioned in the answer by @lloiacono is bogus or is that a separate issue? – Klistrian Jun 3 '15 at 11:35
  • So if you see grey artifacts on your images, then it's most likely a Gd2 issue, there is lot of post about this. I think it makes sense to use imagemagic instead – lloiacono Jun 3 '15 at 11:39
  • Got it, the Gd2 issue does not affect the compression. I'll try fixing the compression first and see if our designers are happy with that. – Klistrian Jun 3 '15 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.