Drawing graphic lines using PHP GD SupportIf you have installed GD library then let us try to draw some lines in an image using gd support. We will open our file in a new window as we have to tell browser ( through header ) that we are sending image.
Using gd we will first learn how to draw line. We will learn some basic functions used in creating and managing images.
The above line creates and image identifier of width 100 and height 200. The top left coordinate is set as 0, 0
Background color is set here for the image with the identifier $im. Here we have set it to a light gray background. The color of the background can be changed by changing the values of red, green, blue ( now all are set to 234 to create light gray background)
Same way let us set a text color for the image
The above line will show the line from where to where it is to be drawn. Staring from $x1,$x2 to $x2, $y2. Note that top left is at the coordinate 0,0. The lines below will give how the line will appear with different values of the coordinates used in imageline function.
Now with this image, let us draw
With the above knowledge, you can see that the command imageline ($im,$x1,$y1,$x2,$y2,$text_color) draws lines between two points defined with two coordinates. To learn the different images we get ( or different lines ) with the change in value of coordinates ( x and y ) we will list a set of values and corresponding image link. Click the link right of the coordinates to check what image will be drawn with the value given at left. All images will be opened in a new window.
With above example you can see how the coordinates affect the line inside the image. Now let us dray two lines in the same image one after the other.
Above examples must have given you some idea on how to draw lines using gd support in PHP. You can use the forum if you have any doubt. Now here you can see the code we used to draw the lines in small window. Note that this code has two imageline functions to draw two lines. Change the data and see how the line changes.
Save the above code in a file and open it without adding any html code or data to it. With this learning on how to draw lines we will move to our next learning.