Summary of Some graph functions and function parameters of the GD library in PHP (1)

Source: Internet
Author: User
? Php $ imgimagecreatetruecolor (600,600); Create a 600px * 600px true color image $ cornflowerblueimagecolorallocate ($ img, 100,149,237); imagefill ($ img, $ cornflowerblue ); fill the background color imagefill ($ img, 30, 30, $ cornflowerblue); and

? Php $ img = imagecreatetruecolor (600,600); // create a 600px * 600px true color image $ cornflowerblue = imagecolorallocate ($ img, 100,149,237); imagefill ($ img, 0, 0, $ cornflowerblue); // fill in the background color // imagefill ($ img, 30, 30, $ cornflowerblue); and

 
 

Using the above two pieces of code, I want to express the differences between the image created by imagecreatetruecolor () and imagecreate () and add the background color.

The following code draws a 100px * 100px square from (10, 10). The 100px * 100px square includes the pixel of the border. The border of this square is 1 pixel, and the two pixels of the blank pixel plus two borders are 100 pixels:

 
After careful measurement, the border of a square is drawn from (11, 11) and (110,110. Therefore, if we want to add a border for this 600px * 600px image:
 


Let's look at it again:

 
The coordinates of the drawn points are actually (201,301 ).

Circle:

 
The center of the circle is (200,200), plus two pixels of the circular edge. The length of the circle is 101, and the width is 101. The ellipse is similar.

Let's take a look at the performance of the GD function when we draw a line:

 
The coordinates of the first vertex of a line segment are actually (301,301), and the coordinates of the last vertex of the line segment are (401,401 ). Do you understand that the first starting point of the GD function in php is always one pixel larger than the parameter coordinate value specified in the function when drawing a graph.

Let's take a look at the imagefilledarc () function:

 
Shows the effect:



Let's look at an error function imagechar ():

 
For the X axis, it starts to be painted at 101 pixels, but there is a few pixel error in the Y axis.

Imagefontheight (int $ font) returns the pixel value of a character height in the specified font. For example, imagefontheight (15) returns 15.

Array imagettftext (resource$image, Float$size, Float$angle, Int$x, Int$y, Int$color, String$fontfile, String$text), Where x and y are explained as follows:

X:x,yThe coordinates represent the basic points of the first character (probably in the lower left corner of the character ). This andImagestringDifferent, x and y define the upper left corner of the first character. For example, "top left" is 0 and 0.

Y: Y coordinate. It sets the font baseline position, not the bottom of the character.

As soon as I saw the baseline, I was masked and checked the information. Please refer:


In actual display, there are still some deviations in pixels. After all, pixels are only a relative unit. They are related to the resolution of the monitor. Sometimes, errors are inevitable. However, in the case of standard pixels, it is necessary to understand the parameter standards of these functions in the php GD library.

Of course, there are many other functions in GD, so I will not elaborate on them here. Do you have any good ideas or incorrect texts? I hope you will not be able to point out them. I am very grateful.

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.