如何在PHP中使用imagefilledarc()函式繪製部分圓弧並填充它?


imagefilledarc()是PHP中的一個內建函式,用於繪製部分圓弧並填充它。

語法

bool imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style)

引數

imagefilledarc()接受九個引數:$image,$cx,$cy,$width,$height,$start,$end,$color和$style。

  • $image − 由影像建立函式imagecreatetruecolor()返回。此函式用於建立影像的大小。

  • $cx − 設定中心的x座標。

  • $cy − 設定中心的y座標。

  • $width − 設定圓弧寬度。

  • $height − 設定圓弧高度。

  • $start − 開始角度(以度為單位)。

  • $end − 圓弧結束角度(以度為單位)。0度位於三點鐘位置,圓弧按順時針方向繪製。

  • $color − 使用imagecolorallocate()函式建立的顏色識別符號。

  • $style − 建議如何填充影像,其值可以是以下列表中的任何一個:

    • IMG_ARC_PIE

    • IMG_ARC_CHORD

    • IMG_ARC_NOFILL

    • IMG_ARC_EDGED

IMG_ARC_PIEIMG_ARC_CHORD是互斥的。

IMG_ARC_CHORD用一條直線連線起始和結束角度,而IMG_ARC_PIE產生圓角。

IMG_ARC_NOFILL表示應描繪圓弧或弦,而不填充。

IMG_ARC_EDGEDIMG_ARC_NOFILL一起使用,表示應將起始和結束角度連線到中心。

返回值

成功返回True,失敗返回False。

示例1

<?php
   define("WIDTH", 700);
   define("HEIGHT", 550);

   // Create the image.
   $image = imagecreate(WIDTH, HEIGHT);

   // Allocate colors.
   $bg = $white = imagecolorallocate($image, 0x00, 0x00, 0x80);
   $gray = imagecolorallocate($image, 122, 122, 122);

   // make pie arc.
   $center_x = (int)WIDTH/2;
   $center_y = (int)HEIGHT/2;
   imagerectangle($image, 0, 0, WIDTH-2, HEIGHT-2, $gray);
   imagefilledarc($image, $center_x, $center_y, WIDTH/2,
   HEIGHT/2, 0, 220, $gray, IMG_ARC_PIE);

   // Flush image.
   header("Content-Type: image/gif");
   imagepng($image);
?>

輸出

示例2

<?php
   // Created the image using imagecreatetruecolor function.
   $image = imagecreatetruecolor(700, 300);
   
   // Allocated the darkgray and darkred colors
   $darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
   $darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);

   // Make the 3D effect
   for ($i = 60; $i > 50; $i--) {
      imagefilledarc($image, 100, $i, 200, 100, 75, 360, $darkred, IMG_ARC_PIE);
   }
   imagefilledarc($image, 100, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE);

   // flush image
   header('Content-type: image/gif');
   imagepng($image);
   imagedestroy($image);
?>

輸出

更新於:2021年8月9日

302 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告