Magento调整大小()图像质量:脏白色背景

dig*_*wig 9 thumbnails magento gd2

我有一个客户对他们的产品缩略图在Magento上呈现的方式非常不满意.

两个帐户的狡猾外观是显而易见的:

  • 有一个肮脏的白色背景,有非常浅灰色的水平线
  • 其次,颜色会有轻微的损失(失去对比度和饱和度).

我已经删除了所有压缩,将所有质量设置为100%,刷新了图像缓存,进行了实验,破解,并将其修复了几十次,似乎没有任何效果.

这个版本的Magento是ver.1.4.2.0

有没有人在这里遇到同样的问题,如果是这样,你设法解决它?

Jas*_*ten 22

问题与lib/Varien/Image/Adapter/Gd2.php中的resize函数中的php函数imagecopyresampled有关,为了使图像平滑调整,会出现一些舍入问题.

我的解决方案是在调整图像大小后,简单地将图像中的任何非常浅的灰色像素更改为纯白色.为此,首先将lib/Varien/Image/Adapter/Gd2.php复制到app/code/local/Varien/Image/Adapter/Gd2.php

接下来在resize函数内找到以下代码(第312行)

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

然后在下面添加以下代码:

// 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);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

从Magento中的缓存管理中刷新图像缓存,您应该为新显示器提供更好的图像.实现此功能时,很少有注意事项,第一次生成图像时会有很小的性能下降,带有阴影的图像可能会有更清晰的边缘,因为已经去除了非常浅的灰色.


Ale*_*lex 6

试试下面的例子

echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(180, 210)->setQuality(50);
Run Code Online (Sandbox Code Playgroud)