【发布时间】:2012-12-06 06:22:17
【问题描述】:
我最近刚刚给Adaptive Images 打了一针。
它似乎工作正常,除了转换透明 PNG 时。我有一个图像,它只是透明背景上的一个弯曲的白色形状。当图像被自适应图像(我相信它使用 GD 库进行转换)转换时,白色形状的边缘会出现黑色边框。
下面是带有黑色边框的弯曲边缘的屏幕截图,因此您可以了解我的意思。
原始尺寸 1920x63:http://i.imgur.com/Cc0hJ.png
我对 GD 库或它如何转换图像知之甚少,但我确实做了一些搜索,看看它是否对我有用。不过我不这么认为。
我还发现了 this similar post 与同一问题有关。但是,我尝试编辑 Adaptive Images PHP 以使用@WouterH 建议的答案,但它没有用。他建议创建一种透明颜色,并在复制之前用该颜色填充 $image。代码如下:
$transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $transparent);
imagealphablending($image, true);
在adaptive-images.php 文件中,我找到了以下代码行:
imagealphablending($dst, false);
imagesavealpha($dst,true);
$transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent);
这是我进行更改的地方。由于我不确定正确的顺序是什么,因此我尝试了许多变体,但在大多数情况下,我尝试将其调整为以下内容:
imagesavealpha($dst,true);
$transparent = imagecolorallocatealpha($dst, 0, 0, 0, 127);
imagefill($image, 0, 0, $transparent);
imagealphablending($dst, true);
imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent);
这似乎没有任何区别。根据我尝试的不同方法,我要么为以前透明的任何地方填充黑色,要么仍然存在相同的问题(黑色轮廓)。
希望有人能帮我解决这个问题...提前致谢!
【问题讨论】:
标签: image image-processing png gd responsive-design