Magento – Disable magento’s compression of product images

ce-1.9.0.1imagemagento-1.9product-imagesthumbnail

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.

Best Answer

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

Related Topic