imagerotate

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

imagerotate用給定角度旋轉(zhuǎn)圖像

說明

imagerotate(
    resource $image,
    float $angle,
    int $bgd_color,
    int $ignore_transparent = 0
): resource

src_im 圖像用給定的 angle 角度旋轉(zhuǎn)。bgd_color 指定了旋轉(zhuǎn)后沒有覆蓋到的部分的顏色。

旋轉(zhuǎn)的中心是圖像的中心,旋轉(zhuǎn)后的圖像會按比例縮小以適合目標圖像的大小——邊緣不會被剪去。

參數(shù)

image

由圖象創(chuàng)建函數(shù)(例如imagecreatetruecolor())返回的 GdImage 對象。

angle

Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise.

bgd_color

Specifies the color of the uncovered zone after the rotation

ignore_transparent

如果被設(shè)為非零值,則透明色會被忽略(否則會被保留)。

返回值

返回旋轉(zhuǎn)后的圖像資源, 或者在失敗時返回 false。

更新日志

版本 說明
5.1.0 新增: ignore_transparent 。

范例

示例 #1 將圖像旋轉(zhuǎn) 180 度

本例將把一幅圖像旋轉(zhuǎn) 180 度——上下顛倒。

<?php
// File and rotation
$filename 'test.jpg';
$degrees 180;

// Content type
header('Content-type: image/jpeg');

// Load
$source imagecreatefromjpeg($filename);

// Rotate
$rotate imagerotate($source$degrees0);

// Output
imagejpeg($rotate);
?>

以上例程的輸出類似于:

例子的輸出:將圖像旋轉(zhuǎn) 180 度

注釋