如何使用 PHP 中的 imageopenpolygon() 函式繪製一個開放多邊形?


imageopenpolygon() 是 PHP 中的一個內建函式,用於在給定的影像上繪製一個開放多邊形。

語法

bool imageopenpolygon(resource $image,array $points,int $num_points,int $color)

引數

imageopenpolygon() 採用四個不同的引數:$image、$points、$num_points 和$color。

  • $image − 指定要處理的影像資源。

  • $image − 指定要處理的影像資源。

  • $points − 指定多邊形的點。

  • $num_points − 指定點的數量。總的(頂點)點數量必須至少為三個。

  • $color − 此引數指定多邊形的顏色。

返回值

imageopenpolygon() 在成功時返回 True,失敗時返回 False。

示例 1

<?php
   // Create a blank image using imagecreatetruecolor() function.
   $img = imagecreatetruecolor(700, 300);

   // Allocate a color for the polygon
   $col_poly = imagecolorallocate($img, 0, 255, 0);

   // Draw the polygon
   imageopenpolygon($img, array(
      0, 0,
      100, 200,
      400, 200
   ),
   3,
   $col_poly);

   // Output the picture to the browser
   header('Content-type: image/png');
   imagepng($img);
   imagedestroy($img);
?>

輸出

示例 2

<?php
   // Create a blank image using imagecreatetruecolor() function.
   $image = imagecreatetruecolor(700, 300);
   
   // allocate the colors
   $blue = imagecolorallocate($image, 0, 255, 255);

   // Six points of the array
   $points = array(
      60, 130,
      130, 230,
      280, 230,
      350, 130,
      210, 30,
      60, 130
   );
   
   // Create a polygon
   imageopenpolygon($image, $points, 6, $blue);

   // Output to the browser
   header('Content-type: image/png');
   imagepng($image);
   imagedestroy($image);
?>

輸出

更新於:09-08-2021

333 次瀏覽

啟動您的職業生涯

完成該課程,獲得認證

開始學習
廣告