Magento resize()图像质量:肮脏的白色背景 [英] Magento resize() image quality: dirty white background

查看:139
本文介绍了Magento resize()图像质量:肮脏的白色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a client who is seriously unhappy with the way their product thumbnails are rendering on Magento.

在两个帐户上都可以看到狡猾的外表:

The dodgy appearance is noticeable on two accounts:

  • 有一个肮脏的白色背景,水平线很浅
  • 其次,颜色损失很小(对比度和饱和度下降).

我已经删除了所有压缩,将所有质量都设置为100%,刷新了图像缓存,进行了多次尝试,破坏和修复,但似乎无济于事.

I have removed ALL compression, set ALL quality to 100%, flushed image cache, experimented, broken, and fixed it all dozens of times, and nothing seems to work.

此版本的Magento是ver. 1.4.2.0

This version of Magento is ver. 1.4.2.0

这里有人遇到同样的问题吗?如果可以,您是否已解决问题?

Is anyone out here experiencing the same problems, and if so have you managed to fix it?

推荐答案

问题与lib/Varien/Image/Adapter/Gd2.php内的resize函数中的PHP函数imagecopyresampled有关.会产生平滑调整尺寸的图像.

The problem has to do with the php function imagecopyresampled in the resize function inside lib/Varien/Image/Adapter/Gd2.php, there are some rounding issues that occur to make a smoothly resized image.

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

My solution is to simply change any very light grey pixels in the image to pure white after the image has been resized. To do so first copy lib/Varien/Image/Adapter/Gd2.php to app/code/local/Varien/Image/Adapter/Gd2.php

接下来,在调整大小功能内找到以下代码(在第312行附近)

Next find the following code inside the resize function (around line 312)

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

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

Then add the following code underneath:

// 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);
            }
        }
    }
}

从Magento的缓存"管理器中刷新图像缓存,对于新的显示,您应该拥有更好的图像.实施此操作时无需注意的事情是,第一次重新生成图像时性能会受到影响,并且由于去除了非常浅的灰色,带有阴影的图像的边缘可能会更锐利.

Flush the images cache from the Cache management in Magento, and you should have nicer images for the new displays. Few things to note when implementing this, there is a small performance hit the first time you generate the images again, and images with shadows may have sharper edges as the very light greys have been removed.

这篇关于Magento resize()图像质量:肮脏的白色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆