Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
PHP | imagepolygon() Function
Next article icon

PHP | imagepolygon() Function

Last Updated : 15 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The imagepolygon() function is an inbuilt function in PHP which is used to draw a polygon. This function returns TRUE on success and returns FALSE otherwise.
Syntax: 

bool imagepolygon( $image, $points, $num_points, $color )


Parameters: This function accepts four parameters as mentioned above and described below:  

  • $image: The imagecreatetruecolor() function is used to create a blank image in a given size.
  • $points: This parameter is used to hold the consecutive vertices of polygon.
  • $num_points: This parameter contains total number of vertices in a polygon. It must be greater than 3, because minimum three vertices required to create a polygon.
  • $color: This variable contains the filled color identifier. A color identifier created with imagecolorallocate() function.


Return Value: This function returns TRUE on success or FALSE on failure.
Below programs illustrate the imagepolygon() function in PHP.
Program 1:  

php
<?php   // Set the vertices of polygon $values = array(             150,  50, // Point 1 (x, y)             50, 250,  // Point 2 (x, y)             250,  250 // Point 3 (x, y)         );     // Create the size of image or blank image $image = imagecreatetruecolor(300, 300);   // Set the background color of image $background_color = imagecolorallocate($image,  0, 153, 0);    // Fill background with above selected color imagefill($image, 0, 0, $background_color);  // Allocate a color for the polygon $image_color = imagecolorallocate($image, 255, 255, 255);    // Draw the polygon imagepolygon($image, $values, 3, $image_color);    // Output the picture to the browser header('Content-type: image/png');    imagepng($image); ?> 

Output: 

img polygon


Program 2:  

php
<?php   // Set the vertices of 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)             );  // Create the size of image or blank image $image = imagecreatetruecolor(300, 300);   // Set the background color of image $background_color = imagecolorallocate($image,  0, 153, 0);    // Fill background with above selected color imagefill($image, 0, 0, $background_color);  // Allocate a color for the polygon $col_poly = imagecolorallocate($image, 255, 255, 255);   // Draw the polygon imagepolygon($image, $values, 5, $col_poly);   // Output the picture to the browser header('Content-type: image/png');   imagepng($image); ?> 

Output: 

img polygon


Related Articles:  

  • PHP | imagefilledpolygon() Function
  • PHP | imageellipse() Function
  • PHP | imagefilledellipse() Function


Reference: http://php.net/manual/en/function.imagepolygon.php 


Next Article
PHP | imagepolygon() Function

V

Vishal_Khoda
Improve
Article Tags :
  • Web Technologies
  • PHP-function

Similar Reads

    PHP | imageopenpolygon() Function
    The imageopenpolygon() function is an inbuilt function in PHP which is used to draws an open polygon. Syntax: bool imageopenpolygon( resource $image, array $points, int $num_points, int $color ) Parameters: This function accepts four parameters as mentioned above and described below: $image: It spec
    2 min read
    PHP | imagepng() Function
    The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image. Syntax: bool imagepng( resource $image, int $to, int $qual
    2 min read
    PHP | imagesy() Function
    The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati
    1 min read
    PHP | imagefill() Function
    The imagefill() function is an inbuilt function in PHP which is used to fill the image with the given color. This function performs a flood fill starting at the given coordinate (top left is 0, 0) with the given color in the image. Syntax: bool imagefill( $image, $x, $y, $color ) Parameters:This fun
    2 min read
    PHP | imagecrop() Function
    The imagecrop() function is an inbuilt function in PHP which is used to crop an image to the given rectangle. This function crops an image to the given rectangular area and returns the resulting image. The given image is not modified. Syntax: resource imagecrop ( $image, $rect ) Parameters: This fun
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences