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


PHP imagefill()用法及代碼示例

imagefill()函數是PHP中的內置函數,用於用給定的顏色填充圖像。此函數以給定的坐標(圖像的左上角為0、0)開始執行填充。

用法:

bool imagefill( $image, $x, $y, $color )

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


  • $image:它由圖像創建函數之一(例如imagecreatetruecolor())返回。它用於創建圖像的尺寸。
  • $x:該參數用於設置起點的x坐標。
  • $y:該參數用於設置起點的y坐標。
  • $color:它設置圖像的顏色。由imagecolorallocate()函數創建的顏色標識符。

返回值:成功時此函數返回True,失敗時返回False。

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

程序1:

<?php 
  
// Create an image of given size 
$image = imagecreatetruecolor(500, 400); 
  
// Sets background to green 
$green = imagecolorallocate($image, 0, 153, 0); 
imagefill($image, 0, 0, $green); 
  
header('Content-type: image/png'); 
imagepng($image); 
imagedestroy($image); 
?>

輸出:
image filled

程序2:

<?php 
    
// It create the size of image or blank image. 
$image = imagecreatetruecolor(500, 300); 
    
// Set the background color of image. 
$bg = imagecolorallocate($image, 205, 220, 200); 
    
// Fill background with above selected color. 
imagefill($image, 0, 0, $bg); 
   
// Set the color of an ellipse. 
$col_ellipse = imagecolorallocate($image, 0, 102, 0); 
    
// Function to draw the filled ellipse. 
imagefilledellipse($image, 250, 150, 400, 250, $col_ellipse); 
    
// Output of the image. 
header("Content-type: image/png"); 
imagepng($image); 
    
?>

輸出:
image filled

相關文章:

參考: http://php.net/manual/en/function.imagefill.php



相關用法


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