PHP Learning notes--GD Library use

Source: Internet
Author: User

PHP Learning notes--GD Library usePHP Training Tutorial In the GD picture creation process:
1). Set the header to tell the browser which MIME type you want to generate.
2). Create an image area that will be based on this image area in future operations.
3). Draws the fill background in the blank image area.
4). Draw a graphic outline into the background to enter text.
5). Output the final graphic.
6). Clear all resources.
7). Other pages call the image.

Hefei Open Source It education teaching example code:
Header (' content-type:image/png '); Setting the header specifies the MIME output type
$im = Imagecreate (200,200); Create a blank image area
$blue = Imagecolorallocate ($im, 0,102,255);
Imagefill ($im, 0, 0, $blue); Draw a fill background in a blank image area
$white = Imagecolorallocate ($im, 255,255,255);
Imageline ($im, 0, 0, $, a, $white);
Imageline ($im, 0, 0, $white);
Imagestring ($im, 5, N, A, "Mr.Lee", $white);//Draw a graphic outline on the background enter text
Imagepng ($im); Output Final graphic
Imagedestroy ($im); Clear All Resources

Partial code parsing:
Create a new diagram:
int imagecreate (int x_size, int y_size);
Description: This function is used to create an all-empty graph. The parameter x_size, Y_size is the size of the graph, in pixels (pixel).
Example: $im = Imagecreate (400,100);
Match color:
int imagecolorallocate (int im, int red, int green, int blue);
Description: This function is used to match the color of the graphic for use by other drawing functions. The parameter IM represents the handle of the graph. Parameters red, green, blue are the three primary colors of color.
Example: $yellow = Imagecolorallocate ($im, 255,255,128);
Output string
int imagestring (int im, int font, int x, int y, string s, int col);
Description: This function plots a string on a picture. The parameter font is a glyph and is set from 1 to 5 to use the default glyph. The parameter x, Y is the start coordinate of the string. The contents of the string are placed on the parameter S. The parameter col represents the color of the string.
Example: Imagestring ($im, 5, 4, "Graph test!", $white);
Draw a rectangle
Imagerectangle ($im, X1,y1,x2,y2, $color);
Description: Draws a rectangle on the picture. The Parameters x1, y1, and x2, and Y2 are the coordinates of the rectangular diagonal respectively. The parameter col represents the color of the rectangle border.
Example: Imagerectangle ($im. 10,10,40,40, $white);

This article comes from: PHP training, open source it education, open source it education and training

PHP Learning notes--GD Library use

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.