Magento resize() 图像质量:脏白色背景
我有一位客户对其产品缩略图在 Magento 上的呈现方式非常不满意。
这种不可靠的外观在两个方面是显而易见的:
- 有一个肮脏的白色背景,有非常浅灰色的水平线
- ,其次有非常轻微的颜色损失(失去对比度和饱和度)。
我已经删除了所有压缩,将所有质量设置为 100%,刷新图像缓存,进行了数十次实验、破坏和修复,但似乎没有任何效果。
这个版本的 Magento 是 ver. 1.4.2.0
这里有人遇到同样的问题吗?如果有的话,你解决了吗?
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:
- there is a dirty white background which has very light grey horizontal lines
- and secondly there is ever so slight color loss (loses contrast and saturation).
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
该问题与 lib/Varien/Image/Adapter/Gd2.php 内的调整大小函数中的 php 函数 imagecopyresampled 有关,在平滑调整大小的图像时会出现一些舍入问题。
我的解决方案是在调整图像大小后将图像中任何非常浅的灰色像素更改为纯白色。为此,首先将 lib/Varien/Image/Adapter/Gd2.php 复制到 app/code/local/Varien/Image/Adapter/Gd2.php
接下来在调整大小函数中找到以下代码(第 312 行左右)
然后添加以下内容下面的代码:
从 Magento 的缓存管理中刷新图像缓存,您应该为新显示提供更好的图像。实现此操作时需要注意的事项很少,第一次再次生成图像时性能会受到很小的影响,并且带有阴影的图像可能具有更清晰的边缘,因为非常浅的灰色已被删除。
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.
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
Next find the following code inside the resize function (around line 312)
Then add the following code underneath:
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.
尝试下面的例子
try following example
您可以将自己的 Gd2.php 文件放在本地 (app/code/local/Varien/Image/Adapter/Gd2.php) 中,并将质量硬连接到 100%。
质量对我有用,所以我没有这样做。
您还可以在其中放置图像卷积来锐化图像,这样您就可以通过锐化来补偿调整大小的模糊,例如将以下内容放在“调整大小”函数的末尾:
You can put your own Gd2.php file in local (app/code/local/Varien/Image/Adapter/Gd2.php) and hard-wire the quality to 100%.
Quality is working for me so I have not done that.
You can also put an image convolution in there to sharpen your images, in that way you get the blur of a resize compensated for with a sharpen, e.g. put the following just inside the end of the 'resize' function:
我在其中一个项目中遇到了图像质量问题。但问题不是出在后端,而是出在前端。图像质量很差,因为 CSS 中给出的图像宽度和高度与图像文件的宽度和高度不同。
I had problems with images quality on one of projects. But the problem was not on back-end, but on the front-end. Images had bad quality because images width and height given in the CSS was not the same as the image file had.
快速 grep 显示您可以在 Product_image 对象上设置它
quick grep shows that you are able to set this on product_image object
我的一些图像也遇到了同样的问题,后来我意识到那些分辨率较低的图像变得扭曲,尝试使用超过 1100 X 1100 的图像,它应该可以正常工作!
I had the same issue with some of my images, later i realized that those images with lower resolution were getting distorted, try using an image more than 1100 X 1100 and it should work just fine !
将图像上传为 PNG 格式。它们可能不像 JPG 那么小,但它使我们能够避免 Magento 的大小调整功能造成的一些图像质量问题。
Upload the images as PNG's. They may not be as small as JPG, but it allowed us to avoid some image quality issues created by Magento's resizing functionality.