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


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

ImagickDraw::line()函數是PHP的Imagick庫中的內置函數,用於畫線。此函數使用當前筆觸顏色,筆觸不透明度和筆觸寬度繪製線條。

用法:

bool ImagickDraw::line( $sx, $sy, $ex, $ey )

參數:該函數接受上述和以下所述的四個參數:


  • $sx:此參數采用起始x坐標的值。
  • $sy:此參數采用起始y坐標的值。
  • $ex:此參數采用x坐標的結束值。
  • $ey:此參數采用y坐標結尾的值。

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

下麵在PHP中對ImagickDraw::line()函數進行編程:

程序:

<?php 
  
// Create an Imagick object 
$draw = new \ImagickDraw(); 
  
// Function to fill color 
$draw->setFillColor('red'); 
  
// Function to draw line 
$draw->line(10, 30, 180, 200); 
  
// Create Imagick object 
$imagick = new \Imagick(); 
  
// Create new image of given size 
$imagick->newImage(300, 300, 'white'); 
  
// Set the image format 
$imagick->setImageFormat("png"); 
  
// Function to draw the image 
$imagick->drawImage($draw); 
  
header("Content-Type: image/png"); 
  
// Display the output image     
echo $imagick->getImageBlob(); 
?>

輸出:

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



相關用法


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