Part of this is the end of the session to make images with PHP. Actually, outside of functions that will be given still more drawing functions with PHP , your duty to find and develop further. If you really intend to learn it you can refer yourself to the PHP documentation that you can download at www.php.net .
Now, in the previous article you have learned to draw several shapes are like ellipses , lines, boxes, and polygons with ImageArc function , ImageLine , ImageRectangle , and ImagePolygon . There are several functions that use and produce similar elliptical shapes , boxes, and polygons as well but this time these forms are not "empty " but accompanied by a " fill " color . The functions are:
imagefilledarc ( )
imagefilledellipse ( )
imagefilledpolygon ( )
imagefilledrectangle ( )
For imagefilledarc function ( ) and imagefilledellipse ( ) was unknown in PHP versions 4.0.6 and higher and requires GD library 2.0.1 or higher. In principle the use of these functions together with the use of functions provided last week. Here is one example :
<? php
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) ;
ImageFilledRectangle ( $ img , 0,0,200,200 , $ blue ) ;
ImageJPEG ( $ img ) ;
?>
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) ;
ImageFilledRectangle ( $ img , 0,0,200,200 , $ blue ) ;
ImageJPEG ( $ img ) ;
?>
This script produces a blue box picture , not just blue but the ribs are completely blue .
Imagestring function ( ) and ImageStringUp ( )
The second function is used to draw a string . The difference is imagestring function ( ) draw a string with a horizontal position , while ImageStringUp function ( ) draw a string with the vertical position . The syntax is as follows :
The second function is used to draw a string . The difference is imagestring function ( ) draw a string with a horizontal position , while ImageStringUp function ( ) draw a string with the vertical position . The syntax is as follows :
Imagestring ( $ img , font, x , y , string , $ color )
ImageStringUp ( $ img , font, x , y , string , $ color )
font consists of an integer parameter from 1 to 5 to take the built-in font with the value 1 is the smallest font size and the largest five , while the string parameter is the string that will appear as images. The following examples will be given a draw string .
<? php
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) ;
Imagestring ( $ img , 5,30,30 , "Learning PHP " , $ blue ) ;
ImageStringUp ( $ img , 5,150,150 , " Easy lho " , $ red ) ;
ImageJPEG ( $ img ) ;
?>
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) ;
Imagestring ( $ img , 5,30,30 , "Learning PHP " , $ blue ) ;
ImageStringUp ( $ img , 5,150,150 , " Easy lho " , $ red ) ;
ImageJPEG ( $ img ) ;
?>
ImageFillToBorder function ( )
This function will provide color in an area up to certain limits . The syntax is as follows :
This function will provide color in an area up to certain limits . The syntax is as follows :
ImageFillToBorder ( $ img , x , y , limit, $ color )
This function will give color with the color of the parameter $ x , y to meet the limits specified in the parameter limits. Parameter limit is itself a color . Here will be given examples of its use.
<? php
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ black = ImageColorAllocate ( $ img , 0,0,0 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ blue ) ;
ImageArc ( $ img , 150,150,250,175,0,360 , $ white) ;
ImageFillToBorder ( $ img , 150.150 , $ white , $ black ) ;
ImageJPEG ( $ img ) ;
?>
<? php
Header ( " Content-Type : image / jpeg " ) ;
$ img = ImageCreate ( 300.300 ) ;
$ black = ImageColorAllocate ( $ img , 0,0,0 ) ;
$ blue = ImageColorAllocate ( $ img , 0,0,255 ) ;
$ white = ImageColorAllocate ( $ img , 255,255,255 ) ;
ImageFill ( $ img , 0,0 , $ blue ) ;
ImageArc ( $ img , 150,150,250,175,0,360 , $ white) ;
ImageFillToBorder ( $ img , 150.150 , $ white , $ black ) ;
ImageJPEG ( $ img ) ;
?>
In this example, the canvas will be given a blue color , then draw a white ellipse . Then inside it will be black until the black color to see its limits , that is white. If the coordinates of the starting point inside the ellipse, then the black color will fill the ellipse , if the starting point outside the ellipse, then the black canvas that will fill out the field ellipse.
ImageTypes function ( )
This function is used to check what are the different types of images are supported by PHP on the server concerned. The syntax is as follows :
This function is used to check what are the different types of images are supported by PHP on the server concerned. The syntax is as follows :
ImageTypes ( )
This function will produce a bit value corresponding to the image formats are supported, namely IMG_GIF , IMG_JPG , IMG_PNG , and IMG_WBMP . If you want to be checked whether the PHP on the server in question supports the JPEG format , it can be used as follows :
<? php
if ( ImageTypes ( ) & IMG_JPG ) {
echo "PHP supports JPEG format ";
}
?>
if ( ImageTypes ( ) & IMG_JPG ) {
echo "PHP supports JPEG format ";
}
?>
ImageSetPixel function ( )
This function is used to draw a dot ( pixel ) . The syntax is as follows :
This function is used to draw a dot ( pixel ) . The syntax is as follows :
ImageSetPixel ( $ img , x , y , $ color )
Parameters x , y are the coordinates where the point will be drawn, good luck and continue to develop your creativity.
0 komentar:
Post a Comment