透明背景与GD在PHP中

我正在尝试使用PHP和GD创建一个图表.该图表已经有效,但我
无法使背景透明(具有抗锯齿功能).

我想在渐变背景上放置一个消除锯齿的线(这是HTML背景),但它显示了一些白色像素(请参阅下面的图像链接和我的代码).有可能用GD做到这一点吗?我在互联网上搜索了很多,但找不到任何解决方案.

PHP

<?php
$img = imagecreatetruecolor(1000, 1000);

imagesavealpha($img, true);
imagealphablending($img, true);

$color = imagecolorallocatealpha($img, 255, 255, 255, 127); 
$red = imagecolorallocate($img, 255, 0, 0); 

imagefill($img, 0, 0, $color);

imageantialias($img, true);
imageline($img, 10, 10, 500, 20, $red);

header("content-type: image/png");
imagepng($img); 
imagedestroy($img); 
?>

HTML

<style type="text/css">
    body{
        background:url('/Image/background.png');
    }
</style>

<img src="./example.php" />

解决方法:

PHP手册基本上说明你不能:

It does not support alpha components. It works using a direct blend
operation. It works only with truecolor images.

Thickness and styled are not supported.

Using antialiased primitives with transparent background color can end
with some unexpected results. The blend method uses the background
color as any other colors. The lack of alpha component support does
not allow an alpha based antialiasing method.

http://es.php.net/imageantialias

因此,除非有人带有第三方代码或一些诙谐的黑客,否则你运气不好.

上一篇:Django--CSRF 跨站请求伪造


下一篇:php – 用javascript旋转图像或div?