PHP에서 imagefilledpolygon() 함수를 사용하여 채워진 다각형을 그리는 방법은 무엇입니까?

王林
풀어 주다: 2023-09-14 17:46:02
앞으로
949명이 탐색했습니다.

imagefilledpolygon()은 채워진 다각형을 그리기 위한 내장 PHP 함수입니다.

Syntax

bool imagefilledpolygon($image, $points, $num_points, $color)
로그인 후 복사

Parameters

imagefilledpolygon()은 4가지 매개변수($image, $points, $ num_points 및 $color)를 사용합니다.

  • $Image - imagecreatetruecolor() 함수를 사용하여 지정된 크기의 빈 이미지를 만듭니다.

  • $points - 다각형의 연속 꼭지점을 저장합니다.

  • $num_points - 다각형의 총 정점 수를 포함합니다. 다각형을 만들려면 점/정점의 총 개수가 3개 이상이어야 합니다.

  • $color - imagecolorallocate() 함수를 사용하여 채워진 색상 식별자를 포함합니다.

반환 값

성공하면 True, 실패하면 False를 반환합니다.

예제 1

<?php
   // set up array of points for a polygon
   $values = array(
      40, 50, // Point 1 (x, y)
      20, 240, // Point 2 (x, y)
      60, 60, // Point 3 (x, y)
      240, 20, // Point 4 (x, y)
      50, 40, // Point 5 (x, y)
      10, 10 // Point 6 (x, y)
   );
   // create the image using imagecreatetruecolor function
   $img = imagecreatetruecolor(700, 350);

   // allocated the blue and gray colors
   $bg = imagecolorallocate($img, 122, 122, 122);
   $blue = imagecolorallocate($img, 0, 0, 255);

   // filled the background
   imagefilledrectangle($img, 0, 0, 350, 350, $bg);

   // draw a polygon
   imagefilledpolygon($img, $values, 6, $blue);

   // flush image
   header(&#39;Content-type: image/png&#39;);
   imagepng($img);
   imagedestroy($img);
?>
로그인 후 복사

Output

PHP에서 imagefilledpolygon() 함수를 사용하여 채워진 다각형을 그리는 방법은 무엇입니까?

예제 2

<?php
   // Set the vertices of the polygon
   $values = array(
      150, 50, // Point 1 (x, y)
      55, 119, // Point 2 (x, y)
      91, 231, // Point 3 (x, y)
      209, 231, // Point 4 (x, y)
      245, 119 // Point 5 (x, y)
   );
   // It creates the size of the image or blank image.
   $img = imagecreatetruecolor(700, 350);

   // Set the gray background image color
   $bg = imagecolorallocate($img, 122, 122, 122);

   // Set the red image color
   $red = imagecolorallocate($img, 255, 0, 0);

   // fill the background
   imagefilledrectangle($img, 0, 0, 350, 350, $bg);

   // Draw the polygon image
   imagefilledpolygon($img, $values, 5, $red);

   // Output of the image.
   header(&#39;Content-type: image/png&#39;);
   imagepng($img);
   imagedestroy($img);
?>
로그인 후 복사

Output

PHP에서 imagefilledpolygon() 함수를 사용하여 채워진 다각형을 그리는 방법은 무엇입니까?

위 내용은 PHP에서 imagefilledpolygon() 함수를 사용하여 채워진 다각형을 그리는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!