📜  PHP | imagickdraw rotate()函数

📅  最后修改于: 2022-05-13 01:56:33.566000             🧑  作者: Mango

PHP | imagickdraw rotate()函数

ImagickDraw::rotate()函数是PHP的一个内置函数,用于将指定的旋转应用于当前坐标空间。

bool ImagickDraw::rotate( $degrees )

参数:此函数接受单个参数$degrees ,用于保存旋转度数的值。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的ImagickDraw::rotate()函数

方案一:

setStrokeOpacity(1);
   
// Set the stroke color
$draw->setStrokeColor('Green');
   
// Set the Fill Color
$draw->setFillColor('Red');
   
// Set the stroke width
$draw->setStrokeWidth(2);
  
// Draw the rectangle
$draw->rectangle(100, 200, 500, 400);
   
// Set the stroke color
$draw->setStrokeColor('black');
   
// Set the fill color
$draw->setFillColor('lightgreen');
   
// Set the rotation
$draw->rotate(10);
   
// Draw the rectangle
$draw->rectangle(100, 200, 500, 400);
   
//Create an imagick object
$imagick = new \Imagick();
   
// Set the image dimensions
$imagick->newImage(600, 500, 'White');
   
// Set the image format
$imagick->setImageFormat("png");
   
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
   
// Display the image
echo $imagick->getImageBlob();
?>

输出:

方案二:

setStrokeOpacity(1);
   
// Set the stroke color
$draw->setStrokeColor('Green');
   
// Set the Fill Color
$draw->setFillColor('Red');
   
// Set the stroke width
$draw->setStrokeWidth(2);
   
$smoothPointsSet = [
        [ ['x' => 10.0 * 5, 'y' => 10.0 * 5],
          ['x' => 30.0 * 5, 'y' => 90.0 * 5],
          ['x' => 25.0 * 5, 'y' => 10.0 * 5],
          ['x' => 50.0 * 5, 'y' => 50.0 * 5], ]
    ];
   
    foreach ($smoothPointsSet as $points) {
        $draw->bezier($points);
    }
   
// Set the stroke color
$draw->setStrokeColor('black');
   
// Set the fill color
$draw->setFillColor('lightgreen');
   
// Set the rotation angle
$draw->rotate(15);
   
foreach ($smoothPointsSet as $points) {
    $draw->bezier($points);
}
   
// Create an imagick object
$imagick = new \Imagick();
   
// Set the image dimensions
$imagick->newImage(350, 350, 'White');
   
// Set the image format
$imagick->setImageFormat("png");
   
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
   
// Display the image
echo $imagick->getImageBlob();
?>

输出:

参考: http: PHP。 PHP