簡體   English   中英

使用PHP的GD函數,如何創建一個抗鋸齒並具有透明背景的橢圓(帶有alpha的PNG24)?

[英]Using PHP's GD functions, how can I create an ellipse that is anti-alised and has a transparent background (PNG24 with alpha)?

我可以在透明背景上畫一個圓,但是它在邊緣周圍像素化。

我還可以通過http://mierendo.com/software/antialiased_arcs/在非透明背景上獲得一個抗鋸齒的圓圈。

那么,我如何同時獲得兩者呢?

透明圖像的問題在於,邊框處的半透明像素將使用指定為透明顏色的顏色進行部分着色,如果可以忍受,則可以使用指定的抗鋸齒弧庫,只需將以下內容在他們的示例開始時(我使用了優化版本):

include ("./imageSmoothArc_optimized.php");

$img = imageCreateTrueColor( 648, 800 );
imagealphablending($img,true);
$color = imageColorAllocate( $img, 255, 255, 255);
$transparent_color = imageColorAllocate( $img, 0, 0, 0);
imagefill( $img, 5, 5, $transparent_color );
imagecolortransparent($img, $transparent_color);

這將為您提供透明的PNG圖像。 由於我將黑色指定為透明顏色,因此圓圈將在邊緣附近變為黑色,您將只能在深色背景上使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM