如何在 PHP 中使用 imageellipse() 函式繪製橢圓?


imageellipse() 是 PHP 中一個內建函式,用於繪製橢圓。成功時返回 True,失敗時返回 False。

語法

Bool imageellipse($image, $cx, $cy, $width, $height, $color)

引數

imageellipse() 接受六個不同的引數:$image$cx$cy$width$height$color

  • $image − 建立影像的大小。它由影像建立函式之一返回,例如 imagecreatetruecolor()。

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

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

  • $width − 設定橢圓的寬度。

  • $height − 設定橢圓的高度。

  • $color − 設定橢圓的顏色。由 imagecolorallocate() 函式建立的顏色識別符號。

返回值

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

示例 1

<?php
   // Create a blank image.
   $image = imagecreatetruecolor(700, 350);

   // Select the background color.
   $bg = imagecolorallocate($image, 0, 0, 0);

   // Fill the background with the color selected above.
   imagefill($image, 0, 0, $bg);

   // Choose a color for the ellipse.
   $col_ellipse = imagecolorallocate($image, 255, 255, 255);

   // Draw the ellipse.
   imageellipse($image, 325, 175, 500, 175, $col_ellipse);

   // Output the image.
   header("Content-type: image/png");
   imagepng($image);
?>

輸出

示例 2

<?php
   //It creates the blank image or size of the image.
   $image = imagecreatetruecolor(700, 600);

   //Set the background color of the image.
   $bg = imagecolorallocate($image, 122, 122, 122);

   //Fill background with the above-selected color.
   imagefill($image, 0, 0, $bg);

   // set color of the ellipse.
   $col_ellipse = imagecolorallocate($image, 0, 255, 255);

   // Function to draw the ellipse.
   imageellipse($image, 250, 300, 300, 550, $col_ellipse);

   // Output of the image.
   header("Content-type: image/gif");
   imagepng($image);
?>

輸出

更新於: 2021-08-09

640 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.