[英]Transparent background with GD in 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手冊基本上說明你不能:
它不支持alpha組件。 它使用直接混合操作。 它僅適用於真彩色圖像。
厚度和樣式不受支持。
使用具有透明背景顏色的抗鋸齒圖元可以以一些意想不到的結果結束。 混合方法使用背景顏色作為任何其他顏色。 缺少alpha組件支持不允許基於alpha的抗鋸齒方法。
http://es.php.net/imageantialias
因此,除非有人帶有第三方代碼或一些詼諧的黑客,否則你運氣不好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.