如何使用PHP中的imagerotate()函式以給定角度旋轉影像?
imagerotate() 是PHP中的一個內建函式,用於以給定的角度(度數)旋轉影像。
語法
resource imagerotate($image, $angle, $bgd_color, $ignore_transparent = 0)
引數
imagerotate() 接受四個引數:$image,$angle,$bgd_color 和 $ignore_transparent。
$image − 由imagecreatetruecolor()函式返回的$image引數。它用於建立影像的大小。
$angle − $angle引數用於儲存以度為單位的不同旋轉角度。它用於逆時針旋轉影像。
$bgd_color − 儲存旋轉後未覆蓋區域的背景顏色。
$ignore_transparent − $ignore_transparent引數用於設定,如果它非零,則忽略透明顏色。
返回值
成功時,imagerotate() 返回旋轉影像的影像資源;失敗時返回false。
示例1
<?php // Assigned the image file to the variable $image_name = 'C:\xampp\htdocs\test\23.jpg'; // Load the image file using imagecreatefrompng() function $image = imagecreatefromjpeg($image_name); // Use imagerotate() function to rotate the image 90 degree $img = imagerotate($image, 90, 0); // Output the image in the browser header("Content-type: image/png"); imagepng($img); ?>
輸入影像
輸出影像
示例2
<?php // Assigned the image file to the variable $image_name = 'C:\xampp\htdocs\test\23.jpg'; // Load the image file using imagecreatefrompng() function $image = imagecreatefromjpeg($image_name); // Use imagerotate() function to rotate the image 180 degree $img = imagerotate($image, 180, 0); // Output the image in the browser header("Content-type: image/png"); imagepng($img); ?>
輸出
廣告