How PHP uses GD2 to draw geometry

Source: Internet
Author: User
This article mainly introduces PHP using GD2 to draw the geometry, combined with the example form analysis of the common functions involved in GD2 drawing and specific use of skills, the need for friends can refer to the following

This example describes how PHP uses GD2 to draw geometry. Share to everyone for your reference, as follows:

You can use the GD2 function not only to draw line shapes, but also to draw fill shapes, such as filled circles, filled rectangles, and so on. The following is an introduction to the drawing methods used in GD2.

bool imagefill( resource image, int x, int y, int color )

The Imagefill () function performs a region fill with a color color at the coordinates (x, y) of the image image (the upper-left corner (0,0)), which is populated with the same tangent (x, y) point color).

bool imagefilledarc ( resource image , int cx , int cy , int w , int h , int s , int e , int color , int style )

Imagefilledarc () draws an elliptical arc in the image represented by the image as Cx,cy (0, 0) in the upper-left corner. Returns TRUE on success, or returns FALSE.W and h on failure, respectively specifying the width and height of the ellipse, and the S and E parameters specifying the starting and ending points with an angle. The style can be a bitwise or (or) value after the following values:

Img_arc_pie
Img_arc_chord
Img_arc_nofill
Img_arc_edged

Img_arc_pie and Img_arc_chord are mutually exclusive, Img_arc_chord just connect the start and end points with a straight line, and Img_arc_pie produce a circular boundary (if two are used, Img_arc_chord takes effect). Img_arc_nofill indicates that an arc or chord is only outlined, not filled. Img_arc_edged indicates that starting and ending points are connected to the center point with a straight line, and using Img_arc_nofill together is a good way to appeased contour (without padding).

bool imagefilledellipse ( resource image , int cx , int cy , int w , int h , int color )

Imagefilledellipse () draws an ellipse at the center of the image represented by Cx,cy (0, 0 in the upper-left corner of the image). W and H Specify the width and height of the ellipse, respectively. The ellipse is filled with color. Returns TRUE on success, or FALSE on failure.

bool imagefilledrectangle( resource image, int x1, int y1, int x2, int y2, int color )

The function draws a color-filled rectangle in the image, with the upper-left corner coordinates (x1, y1), and the lower-right corner coordinates (x2, y2). (0,0) is the upper-left corner of the image.

For example: Apply as above function, Draw fill circle and fill square, code as follows

<?php  Header ("Content-type:image/png");//Output the image to the browser  $img = Imagecreate (400, 200);//Create a 400x200 canvas  $ BG = imagecolorallocate ($img, 0, 0, 255);//Set background color  $white = imagecolorallocate ($img, 255, 255, 255);//Set Fill color  Imagefilledellipse ($img, +, $white);//Draw filled round  imagefilledrectangle ($img, Max, Max, Max, $white) ;//Draw filled square  imagepng ($img);//Output Image  Imagedestroy ($img) in PNG format;//Release resources

The result of the operation is as follows

The above is the whole content of this article, I hope that everyone's study has helped.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.