function pic_rotating($degrees,$url){
$srcImg = imagecreatefrompng($url); //獲取圖片資源
$rotate = imagerotate($srcImg, $degrees, 0); //原圖旋轉
//獲取旋轉後的寬高
$srcWidth = imagesx($rotate);
$srcHeight = imagesy($rotate);
//創建新圖
$newImg = imagecreatetruecolor($srcWidth, $srcHeight);
//分配顏色 + alpha,將顏色填充到新圖上
$alpha = imagecolorallocatealpha($newImg, 0, 0, 0, 127);
imagefill($newImg, 0, 0, $alpha);
//將源圖拷貝到新圖上,並設置在保存 PNG 圖像時保存完整的 alpha 通道信息
imagecopyresampled($newImg, $rotate, 0, 0, 0, 0, $srcWidth, $srcHeight, $srcWidth, $srcHeight);
imagesavealpha($newImg, true);
//生成新圖
imagepng($newImg, $url);
}
$degrees = 90; //旋轉角度
$url = './111111111111/154020404057861.png'; //圖片存放位置
pic_rotating($degrees,$url);