2014-06-18 93 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*/ 
} 

将该类添加到图像标记。