Making Images With PHP (part 2 )

In the previous article the basic functions we have learned to draw . With these basic functions supposing you are preparing a canvas and drawing tools . Well, this time we learn more by studying the functions that are used for drawing. These are functions for drawing them.
ImageArc function ( )
This function is a function that is used to draw the ellipse , either open or closed curve curve . The syntax is as follows :
ImageArc ( $ img , x , y , l, t , aw , ak , $ color )
This function will draw the ellipse with center in x , y ( 0.0 located in the upper left) , with a height t and width l, and the starting point and end point represented by aw and ak in degrees . Thus , if t and l be filled with the same value , then aw and ak is 0 and 360 , then that is a circle drawn . The following will be given an example for drawing an ellipse .

<?
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ white) ;
ImageArc ( $ img , 150,150,150,280,0,360 , $ blue ) ;
ImageJPEG ( $ img ) ;
?>

To note , during the time in giving examples of PHP scripts , always use HTML tags , beginning with the tag <HTML> , <HEAD> , and so on . But this time the tags are not used , because the function in the script header provides information that the output is sent to the browser has a content-type of image file , not an HTML file .
ImageArc ( $ img , x , y , l, t , aw , ak , $ color )
This function will draw the ellipse with center in x , y ( 0.0 located in the upper left) , with a height t and width l, and the starting point and end point represented by aw and ak in degrees . Thus , if t and l be filled with the same value , then aw and ak is 0 and 360 , then that is a circle drawn . The following will be given an example for drawing an ellipse .
<?
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ white) ;
ImageArc ( $ img , 150,150,150,280,0,360 , $ blue ) ;
ImageJPEG ( $ img ) ;
?>
To note , during the time in giving examples of PHP scripts , always use HTML tags , beginning with the tag <HTML> , <HEAD> , and so on . But this time the tags are not used , because the function in the script header provides information that the output is sent to the browser has a content-type of image file , not an HTML file .
Because the ellipse is drawn starting from 0 to 360 degrees, then the resulting picture will be a closed curve . If such an ellipse is drawn starting from 0 to 180 degrees , then the result is a half- ellipse, or elliptical with an open curve . To draw an ellipse with the curve is always closed, you can use ImageEllipse function . The syntax is as follows :
imageellipse ( $ img , x , y , l, t , $ color )
These new functions are in PHP 4.0.6 and requires GD 2.0.2 or later. This library can get you in http://www.boutell.com/gd .

ImageLine function ( )
This function is used to draw the line . The syntax is as follows :
ImageLine ( $ img , x1 , y1 , x2 , y2 , $ color )
Parameters x1 , y1 are the coordinates of the beginning of the line and x2, y2 are the coordinates of the end of the line . The following examples will be given a line drawing .
<?
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ red = ImageColorAllocate ( $ img , 255,0,0 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ white) ;
ImageLine ( $ img , 0,0,300,300 , $ blue ) ;
ImageLine ( $ img , 0,150,300,150 , $ red ) ;
ImageJPEG ( $ img ) ;
?>
There is a similar function ImageLine ( ) , ie ImageDashedLine ( ) , which used to draw the dotted line . use exactly the same syntax ImageLine function ( ) .
ImageRectangle function ( )
This function is used to draw rectangles . The syntax is as follows :
ImageRectangle ( $ img , x1 , y1 , x2 , y2 , $ color )
Parameters x1 , y1 is the top left point of the rectangle , while the x2 , y2 is the bottom -right point . The following examples will be given a rectangular drawing .
<?
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ red = ImageColorAllocate ( $ img , 255,0,0 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ white) ;
ImageRectangle ( $ img , 0,0,200,200 , $ blue ) ;
ImageJPEG ( $ img ) ;
?>
ImagePolygon function ( )
This function is used to draw polygon (curve a lot or corner lot side ) . The syntax is as follows :
imagepolygon ( $ img , array_sudut , jml_sudut , $ color )
array_sudut parameter is an array containing the coordinates of each polygon vertex , such as $ point [ 0 ] = x1 , $ point [ 1 ] = y1 , $ point [ 2 ] = x2, $ point [ 3 ] = x3 , and so on . jml_sudut parameter is the number of vertex of the polygon will be drawn . The following examples will be given polygon drawing .
<?
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ color = ImageColorAllocate ( $ img , 157,25,12 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ white) ;
$ point [ 0 ] = 0 ;
$ point [ 1 ] = 0 ;
$ point [ 2 ] = 60 ;
$ point [ 3 ] = 30 ;
$ point [ 4 ] = 60 ;
$ point [ 5 ] = 100 ;
$ point [ 6 ] = 120 ;
$ point [ 7 ] = 190 ;
$ point [ 8 ] = 210 ;
$ point [ 9 ] = 60 ;
ImagePolygon ( $ img , $ points , 5 , $ color ) ;
ImageJPEG ( $ img ) ;
?>
Because the polygon will be created with a five point angle , it is necessary to array with 10 components , because each vertex requires two numbers as coordinates. Thus, the example image will have a polygon at the vertex ( 0.0 ) , ( 60.30 ) , ( 60.100 ) ( 120.190 ) , and ( 210.60 ) . From these examples you can see that basically drawing a line programming with PHP is quite simple . Flow programming is as follows :
  • First send the image header contains information that will be produced .
  • Both create an image with ImageCreate function
  • Third allocate colors to be used
  • Fourth Color canvas with one color that has been allocated
  • Fifth draw a figure with the image functions we will study this .
  • Last "print" the image with the image output functions .

Well good luck to see the results .

0 komentar:

Post a Comment