2012-09-01 100 views
1

我在旋轉PNG圖像時遇到了問題,並且保持質量與未旋轉時一樣高。它也失去了透明度。以透明度在PHP中旋轉PNG

下面是我用旋轉它的代碼:

$source = imagecreatefrompng('cake-test.png'); 
$col = imagecolorexact($source, 255, 255, 255); 
imagecolortransparent($source, $col) ; 
$rotate = imagerotate($source, 10, 0); 

imagepng($rotate, 'temp.png') ; 

創建的圖像看起來邊緣周圍的所有別名,並沒有任何透明度。有誰知道如何讓它工作或有他們願意分享的功能?


謝謝!我在圖像所在的div上設置了背景,現在看起來很好。

回答

2

您必須爲imagecolorallocatealpha分配alpha通道並將imagesavealpha設置爲true。 試試這個:

$source = imagecreatefrompng('cake-test.png'); 
$bgColor = imagecolorallocatealpha($source, 255, 255, 255, 127); 
$rotate = imagerotate($source, 10, $bgColor); 
imagesavealpha($rotate, true); 

imagepng($rotate, 'temp.png') ;