當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP ImagickDraw rotate()用法及代碼示例


ImagickDraw::rotate()函數是PHP的內置函數,用於將指定的旋轉應用於當前坐標空間。

bool ImagickDraw::rotate( $degrees )

參數:該函數接受單個參數$degrees,該參數用於保存旋轉度的值。

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


以下示例程序旨在說明PHP中的ImagickDraw::rotate()函數:

程序1:

<?php 
  
// require_once('path/vendor/autoload.php'); 
   
// Create an Imagick Draw object 
$draw = new \ImagickDraw(); 
   
// Set the stroke color 
$strokeColor = new \ImagickPixel('Green'); 
   
// Set the fill color 
$fillColor = new \ImagickPixel('Red'); 
   
// Set the stroke opacity 
$draw->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(); 
?>

輸出:

程序2:

<?php 
  
// require_once('path/vendor/autoload.php'); 
   
// Create an Imagick Draw object 
$draw = new \ImagickDraw(); 
   
// Set the stroke color 
$strokeColor = new \ImagickPixel('Green'); 
   
// Set the fill color 
$fillColor = new \ImagickPixel('Red'); 
   
// Set the stroke opacity 
$draw->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.net/manual/en/imagickdraw.rotate.php



相關用法


注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 PHP | ImagickDraw rotate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。