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


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


ImagickDraw::polyline()函數是PHP的Imagick庫中的內置函數,該函數用於使用指定的坐標數組使用當前筆觸,筆觸寬度以及填充顏色或紋理繪製折線。

用法:

bool ImagickDraw::polyline( $coordinates )

參數:該函數接受單個參數$coordinates,該參數用於將點的坐標保存為數組。


返回值:成功時此函數返回True。

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

程序1:

<?php 
  
// Create an ImagickDraw Object 
$draw = new ImagickDraw(); 
  
// Set Stroke Opacity 
$draw->setStrokeOpacity(1); 
  
// Set Stroke Color 
$draw->setStrokeColor('green'); 
  
// Set Fill Color 
$draw->setFillColor('red'); 
  
// Set Stroke Width 
$draw->setStrokeWidth(5); 
  
// Define the points at which lines to be draw 
$points = [ 
        ['x' => 40 * 5, 'y' => 10 * 5], 
        ['x' => 20 * 5, 'y' => 20 * 5], 
        ['x' => 70 * 5, 'y' => 50 * 5], 
        ['x' => 60 * 5, 'y' => 15 * 5] 
    ]; 
  
// Call Polyline Function 
$draw->polyline($points); 
  
// Create an Imagick Object 
$image = new Imagick(); 
  
// Create new Image 
$image->newImage(500, 300, 'white'); 
  
// Set Image Format 
$image->setImageFormat("png"); 
  
// Draw Image 
$image->drawImage($draw); 
  
header("Content-Type: image/png"); 
  
// Display the output image 
echo $image->getImageBlob(); 
?>

輸出:

程序2:

<?php 
  
// Create an ImagickDraw Object 
$draw = new ImagickDraw(); 
  
// Set Stroke Opacity 
$draw->setStrokeOpacity(1); 
  
// Set Stroke Color 
$draw->setStrokeColor('Black'); 
  
// Set Fill Color 
$draw->setFillColor('Green'); 
  
// Set Stroke Width 
$draw->setStrokeWidth(3); 
  
// Define the points at which lines to be draw 
$points = [ 
        ['x' => 40 * 5, 'y' => 10 * 5], 
        ['x' => 20 * 5, 'y' => 20 * 5], 
        ['x' => 70 * 5, 'y' => 50 * 5], 
        ['x' => 40 * 5, 'y' => 10 * 5] 
    ]; 
  
// Set the Font Size  
$draw->setFontSize(50);  
    
// Set the font family  
$draw->setFontFamily('Ubuntu-Mono');  
    
// Set the text to be added  
$draw->annotation(30, 40, "GeeksForGeeks");  
  
// Call Polyline Function 
$draw->polyline($points); 
  
// Create an Imagick Object 
$image = new Imagick(); 
  
// Create new Image 
$image->newImage(500, 300, 'white'); 
  
// Set Image Format 
$image->setImageFormat("png"); 
  
// Draw Image 
$image->drawImage($draw); 
  
header("Content-Type: image/png"); 
  
// Display the output image 
echo $image->getImageBlob(); 
?>

輸出:

參考: http://php.net/manual/en/imagickdraw.polyline.php



相關用法


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