Wie zeichne ich ein gefülltes Polygon mit der Funktion imagefilledpolygon() in PHP?

王林
Freigeben: 2023-09-14 17:46:02
nach vorne
950 Leute haben es durchsucht

imagefilledpolygon() ist eine integrierte PHP-Funktion zum Zeichnen gefüllter Polygone.

Syntax

bool imagefilledpolygon($image, $points, $num_points, $color)
Nach dem Login kopieren

Parameter

imagefilledpolygon() benötigt vier verschiedene Parameter – $image, $points, $ num_points und $color.

  • $Image – Erstellt ein leeres Bild mit bestimmten Abmessungen mithilfe der Funktion imagecreatetruecolor().

  • $Punkte – Speichert die aufeinanderfolgenden Eckpunkte eines Polygons.

  • $num_points – Enthält die Gesamtzahl der Eckpunkte im Polygon. Die Gesamtzahl der Punkte/Eckpunkte muss mindestens drei betragen, um ein Polygon zu erstellen.

  • $color – Enthält Farbkennungen, die mit der Funktion imagecolorallocate() ausgefüllt werden.

Rückgabewert

Gibt „True“ zurück, wenn erfolgreich, und „False“, wenn es fehlschlägt.

Beispiel 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);
?>
Nach dem Login kopieren

Ausgabe

Wie zeichne ich ein gefülltes Polygon mit der Funktion imagefilledpolygon() in PHP?

Beispiel 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);
?>
Nach dem Login kopieren

Ausgabe

Wie zeichne ich ein gefülltes Polygon mit der Funktion imagefilledpolygon() in PHP?

Das obige ist der detaillierte Inhalt vonWie zeichne ich ein gefülltes Polygon mit der Funktion imagefilledpolygon() in PHP?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
Quelle:tutorialspoint.com
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!