Add row and column labels to a chart using the GD2 function (PHP graphic image typical application tutorial 5)

Source: Internet
Author: User
Tags image identifier
add row and column labels to a chart using the GD2 function (PHP graphic image typical application tutorial 5)

The application of the chart in the data is very extensive, is also very use, through the data chart can the complex data visualization display, then we this article is the main explanation to the chart to add the row and the column operation Method!

Let's go back to the previous article, "Using the GD2 function to draw geometry (a typical application of PHP graphic images 4)", which we introduced in the previous article using the GD2 function to draw the geometry, but also introduced our image processing of several common functions, then we today to introduce the chart to add row and column labels!

The technical points of this article:

We still need to apply the GD2 function to add row and column labels to the chart, some of which we have described in detail in previous articles, and now we introduce several functions!

(1) imagecreatefrompng () function

This function is used to get the picture file in PNG format, which has the following syntax:

Resource Imagecreatefrompng (String $filename)

Imagecreatefrompng () returns an image identifier that represents the image obtained from the given file name.

(2) Imageline () function

The function is used to draw a solid line, and the syntax of the function is as follows:

BOOL Imageline (resource $image, int $x 1, int $y 1, int $x 2, int $y 2, int $color)

The function draws a solid line in the image from coordinates (X1,Y1) to (x2,y2) with a color color, and the origin (0,0) is the upper-left corner of the image pair.

(3) imagestring () function

This function is used to draw a line of strings horizontally on the image, with the following syntax:

BOOL Imagestring (resource $image, int $font, int $x, int $y, string $s, int $col)

The parameter font is a glyph, set to 1 to 5 to use the default glyph, parameter x, Y is the start of the string, the contents of the string are placed in the parameter s, and the parameter col represents the color of the string!

Implementation process

<?phpheader ("content-type:text/html; Charset=utf-8 "); $im = Imagecreatefrompng (" Upfile/2.png "); Load a png format picture $black = Imagecolorallocate ($im, 255,0,0); Set the color value, Imageline ($im, 0,20,0,532, $black);         Set Y axis ordinate imageline ($im, 0,437,585,437, $black);      Set X axis ordinate imagestring ($im, 10,0,5, "Y", $black);       Output character yimagestring ($im, 10,560,422, "X", $black);   Output character ximagepng ($im, "a.png");                    echo  "

The results of the output are as follows:

Attention:

The Imagepng () function is sent in PNG format to the browser, if the user requires a different format output, should call its corresponding function, Ruyi gif format sent, should call the Imagegif () function.

About adding row and column labels to a chart here, isn't it simple, here we continue to introduce the chart analysis product data, please read the "Use GD2 function to achieve chart Analysis product data (PHP graphic image of the typical application tutorial 6)"!

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.