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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。