2010-11-11 24 views
8

我昨天整天試圖弄清楚這一點。我通過imagerotate()旋轉圖像。我得到一個黑色的背景,圖像不再覆蓋。我已經試過各種我想不出來作出這樣的背景透明..爲什麼我不能在使用php旋轉後使png透明背景?

這裏是我當前的代碼..

function rotate($degrees) { 
     $image = $this->image; 
     imagealphablending($image, false); 
     $color = imagecolorallocatealpha($image, 0, 0, 0, 127); 
     $rotate = imagerotate($image, $degrees, $color); 
     imagecolortransparent($rotate, $color); 
     imagesavealpha($image, true); 
     $this->image = $rotate; 
    } 

我真的開始變得勾掉。有人可以給我看一些工作代碼嗎?請?

難道我的WAMP服務器和Dreamweaver有問題嗎?因爲我甚至試過這個.. http://www.exorithm.com/algorithm/view/rotate_image_alpha它仍然熄滅無論是黑色或白色背景..

+2

彷彿就在昨天的問題的副本。 http://stackoverflow.com/questions/4148774/how-do-i-get-a-transparent-background-after-rotaing-a-png-image-with-php/4148805 – stevelove 2010-11-11 18:59:52

+0

是的。我知道我真的不應該再次發佈,但你不知道我想這個代碼有多嚴重,只是工作已經.. – Chris 2010-11-11 19:07:31

+0

請指定您的PHP版本。 – Rolf 2010-12-06 12:07:27

回答

1

嘗試設置imagesavealpha()在您的旋轉圖像。

當前您正在原始圖像上運行imagesavealpha()。 [例如。 imagesavealpha($ image,true); ]

相反,你要運行imagesavealpha()旋轉的圖像,然後設置$這個 - >圖像...嘗試:

... 
    $rotate = imagerotate($image, $degrees, $color); 
    imagecolortransparent($rotate, $color); 
    imagesavealpha($rotate, true); // <- using $rotate instead of $image 
    $this->image = $rotate; 

}