当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。