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


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


ImagickDraw::getStrokeLineCap()函數是PHP中的一個內置函數,用於獲取在打開的子路徑被描邊時要使用的形狀。

用法:

int ImagickDraw::getStrokeLineCap( void )

參數:此函數不接受任何參數。


返回值:此函數返回與LINECAP常量之一相對應的整數值。

LINECAP常量列表如下:

  • imagick::LINECAP_UNDEFINED(0)
  • imagick::LINECAP_BUTT(1)
  • imagick::LINECAP_ROUND(2)
  • imagick::LINECAP_SQUARE(3)

異常:該函數在錯誤時引發ImagickException。

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

程序1:

<?php 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
    
// Get the stroke line cap 
$lineCap = $draw->getStrokeLineCap(); 
echo $lineCap; 
?>

輸出:

1 // Which corresponds to imagick::LINECAP_BUTT

程序2:

<?php 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
    
// Set the stroke line cap 
$draw->setStrokeLineCap(3); 
  
// Get the stroke line cap 
$lineCap = $draw->getStrokeLineCap(); 
echo $lineCap; 
?>

輸出:

3 // Which corresponds to imagick::LINECAP_SQUARE

程序3:

<?php 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
    
// Create a new imagick object 
$imagick = new Imagick(); 
    
// Create a image on imagick object 
$imagick->newImage(800, 250, 'black'); 
    
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
    
// Set the fill color 
$draw->setFillColor('black'); 
    
// Set the color of stroke 
$draw->setStrokeColor('white'); 
  
// Set the stroke width 
$draw->setStrokeWidth(3); 
    
// Set the font size 
$draw->setFontSize(25); 
   
 // Set the stroke dash array 
$draw->setStrokeDashArray([20, 5, 19, 15, 5, 15]); 
   
// Draw a rectangle 
$draw->rectangle(100, 50, 225, 175); 
    
// Annotate a text 
$draw->annotation(10, 220, 'The strokeLineCap here is '
         . $draw->getStrokeLineCap()); 
   
// Set the stroke line cap 
$draw->setStrokeLineCap(2); 
    
// Draw a rectangle 
$draw->rectangle(500, 50, 625, 175); 
    
// Annotate a text 
$draw->annotation(400, 220, 'The strokeLineCap here is '
         . $draw->getStrokeLineCap()); 
    
// Render the draw commands 
$imagick->drawImage($draw); 
    
// Show the output 
$imagick->setImageFormat('png'); 
header("Content-Type: image/png"); 
echo $imagick->getImageBlob(); 
?>

輸出:

參考: https://www.php.net/manual/en/imagickdraw.getstrokelinecap.php



相關用法


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