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


PHP ImagickDraw translate()用法及代码示例


ImagickDraw::translate()函数是PHP中的内置函数,用于将平移应用于当前坐标系。它将平移应用于当前坐标系,从而将坐标系原点移动到指定坐标。

用法:

bool ImagickDraw::translate( $x, $y )

参数:该函数接受上述和以下描述的两个参数:


  • $x:此参数用于保存x平移坐标的值。
  • $y:此参数用于保存y平移坐标的值。

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

以下示例程序旨在说明PHP中的ImagickDraw::translate()函数:

示例1:

<?php 
  
// require_once('path/vendor/autoload.php'); 
  
// Create a ImagickDraw object to draw into. 
$draw = new ImagickDraw(); 
  
// Set the stroke color 
$draw->setStrokeColor('black'); 
  
// Set the Image Filled Color 
$draw->setFillColor('red'); 
  
// Draw the circle 
$draw->circle(250, 250, 100, 150); 
   
// Set the Image Filled Color 
$draw->setFillColor('green'); 
  
// Set the translation points 
$draw->translate(90, 30); 
  
// Draw the circle 
$draw->circle(350, 350, 250, 350); 
   
// Create new imagick object 
$image = new Imagick(); 
  
// Set the dimensions of the image 
$image->newImage(500, 500, 'white'); 
  
// Set the image format 
$image->setImageFormat("png"); 
  
// Draw the image 
$image->drawImage($draw); 
header("Content-Type: image/png"); 
  
// Display the image 
echo $image->getImageBlob(); 
?>

输出:
translate()

示例2:

<?php 
  
// require_once('path/vendor/autoload.php'); 
   
// Create a ImagickDraw object to draw into. 
$draw = new ImagickDraw(); 
   
// Set the Stroke color 
$draw->setStrokeColor('black'); 
   
// Set the image filled color  
$draw->setFillColor('red'); 
$points = [['x' => 40 * 5, 'y' => 10 * 5],  
           ['x' => 70 * 5, 'y' => 50 * 5],  
           ['x' => 60 * 5, 'y' => 15 * 5], ]; 
   
// Draw the polygon 
$draw->polygon($points); 
   
// Set the image filled color  
$draw->setFillColor('green'); 
   
// Set the translation points 
$draw->translate(10, 30); 
$points = [['x' => 40 * 5, 'y' => 10 * 5],  
           ['x' => 70 * 5, 'y' => 50 * 5],  
           ['x' => 60 * 5, 'y' => 15 * 5], ]; 
   
// Draw the polygon 
$draw->polygon($points); 
   
// Set the image filled color  
$draw->setFillColor('blue'); 
   
// Set the translation points 
$draw->translate(10, 30); 
$points = [['x' => 40 * 5, 'y' => 10 * 5],  
           ['x' => 70 * 5, 'y' => 50 * 5],  
           ['x' => 60 * 5, 'y' => 15 * 5], ]; 
   
// Draw the polygon 
$draw->polygon($points); 
   
// Set the image filled color 
$draw->setFillColor('yellow'); 
   
// Set the translation points 
$draw->translate(10, 30); 
$points = [['x' => 40 * 5, 'y' => 10 * 5],  
           ['x' => 70 * 5, 'y' => 50 * 5],  
           ['x' => 60 * 5, 'y' => 15 * 5], ]; 
   
// Draw the polygon 
$draw->polygon($points); 
   
// Create new imagick object 
$image = new Imagick(); 
   
// Set the image dimensions 
$image->newImage(400, 400, 'white'); 
   
// Set the image format 
$image->setImageFormat("png"); 
   
// Draw the image  
$image->drawImage($draw); 
header("Content-Type: image/png"); 
   
// Display the image 
echo $image->getImageBlob(); 
?>

输出:

参考: http://php.net/manual/en/imagickdraw.translate.php



相关用法


注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 PHP | ImagickDraw translate() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。