旋转图像后,更改背景

时间:2014-06-18 07:36:50

标签: php css

它只在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' >";

3 个答案:

答案 0 :(得分:1)

只需使用css。因为你也标记了它。

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

将该类添加到图像标记。

答案 1 :(得分:0)

首先:* .jpg不支持透明度。 使用* .png图片格式。

第二:检查一下: How do i get a transparent background after rotaing a png image with php?

答案 2 :(得分: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' >";