问题描述
我有一个客户对他们的产品缩略图在 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
接下来在resize函数中找到以下代码(约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() 图像质量:肮脏的白色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!