【问题标题】:Adaptive Images / GD converted tansparent PNG has black border自适应图像/高清转换透明 PNG 有黑色边框
【发布时间】: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


    【解决方案1】:

    恕我直言,这与此处描述的问题相同: “你所拥有的不是具有 alpha 通道的真彩色 PNG,而是具有透明颜色的索引色 PNG。” PHP GD resizing transparent image giving black border

    【讨论】:

    • 我很难相信这与我从 Photoshop 保存文件的方式有关。我另存为 PNG-24,检查透明度。就这么简单。我只是不明白除了this guythis guy 之外没有其他人遇到过这些问题。而且这些线程都没有提供可行的解决方案...
    猜你喜欢
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 2018-10-04
    • 2011-05-02
    • 2012-06-25
    • 2013-03-17
    • 2012-05-09
    相关资源
    最近更新 更多