php 图片旋转后 背景透明

/**
* 图片旋转
* @date 2019-05-14
* @param integer $degrees [description]
* @param string $bg_img_url [description]
* @return [type] [description]
*/
public function rotate( $degrees=12, $bg_img_url=” ){
$bg_color = 0;
if($bg_img_url){
$bg_color = imagecolorallocatealpha(imagecreatefrompng($bg_img_url), 0, 0, 0, 127);
}
$img = imagerotate($this->img, $degrees, $bg_color);

if($img==false){
throw new \Exception(‘图片旋转失败’);
}
$this->img = $img;
return $this;
}