2014-06-18 95 views
0

它只在PHP中完成,旋轉原始圖像後,圖像的背景是黑色的。如何消除背景? enter image description here旋轉圖像後,更改背景

下面是我的代碼..

 $imgNames = "upload/".$_SESSION["img"]; 
     $sourcea=imagecreatefromjpeg($imgNames); 
     $rotatea=imagerotate($sourcea, 0,0); 
     $uniqids = uniqid(); 
     $rotImages = "upload/".$uniqids.".jpg"; 
     $uni=uniqid(); 
     imagejpeg($rotatea,$rotImages,$q=25); 
     echo "Rotated Image: <img src='$rotImages' >"; 
+0

因爲它是包含黑色背景的源圖像,所以您需要更改旋轉代碼。如果你想要一個透明的背景,你不能使用.jpg,因爲它不能透明。 –

+0

http://www.php.net/manual/en/function.imagefill.php – Bora

回答

0
Add following code 



    $imgNames = "upload/".$_SESSION["img"]; 
     $sourcea=imagecreatefromjpeg($imgNames); 
    $transColor = imagecolorallocatealpha($imgNames, 255, 255, 255, 127); 
     $rotatea=imagerotate($sourcea, 0,$transColor); 
     imagesavealpha($rotateae, true); 
    $uniqids = uniqid(); 
     $rotImages = "upload/".$uniqids.".png"; 
     $uni=uniqid(); 
     imagejpeg($rotatea,$rotImages,$q=25); 
     echo "Rotated Image: <img src='$rotImages' >"; 
+0

什麼是變量$ destimg意味着什麼? – jerome

+0

現在就試試.. $ imgNames是$ destimg –

+0

我認爲必須使用$ sourcea而不是$ imgNames。它的工作原理,但另一個疑問是必須改變透明背景。怎麼做? – jerome

1

只需使用CSS。因爲你也是這樣。

.rotated{ 
transform:rotate(45deg); 
-ms-transform:rotate(45deg); 
-webkit-transform:rotate(45deg); 
/*Or whatever deg you want*/ 
} 

將該類添加到圖像標記。