<? phpinfo ( ) ; ? >
For users of Linux , run the file and check the configure command if there are the following commands :
- With- gd
- With- jpeg - dir = [ namadirektori ]
- With- png - dir = [ namadirektori ]
If there is , then you use PHP can be used to produce images with extension. jpg or. png . You can also check in and check whether the gd GD Support, Support JPG , and PNG Support enabled everything .
If all does not exist, then you must install their own additional libraries required . There are at least two additional libraries are needed , ie jpeg - 6b and the gd library . Here are the installation steps :
Installing jpeg - 6b
To get jpeg - 6b , you can download it from ftp://ftp.uu.net/graphics/jpeg/ . Download the file called jpegsrc.v6b.tar.gz . After that steps should be done is as follows :
Installing gd library
To get the gd library , you can download it from http://www.boutell.com/gd/ . As much as possible download the newest version . installation steps are as follows :
Installing jpeg - 6b
To get jpeg - 6b , you can download it from ftp://ftp.uu.net/graphics/jpeg/ . Download the file called jpegsrc.v6b.tar.gz . After that steps should be done is as follows :
# gunzip jpegsrc.v6b.tar.gzIf after the tests make no mistake that appears, then do this:
# tar - xvf jpegsrc.v6b.tar
# cd [directory jpeg - 6b ]
# . / configure
# Make
# Make test
# make installThese installation steps performed on the distribution of RedHat 7.1. For other distribution installations the same way , only when necessary may have to modify the Makefile file . For more details you can refer to files located in directories install.doc jpeg - 6b .
Installing gd library
To get the gd library , you can download it from http://www.boutell.com/gd/ . As much as possible download the newest version . installation steps are as follows :
# gunzip gd - x.x.x.tar.gz
# tar - xvf gd - x.x.x.tar
# cd [directory - gd x.x.x ]
On RedHat Linux distribution ( and perhaps other distribution ) , most likely you 'll need to modify the Makefile file as follows :
- On the line that reads - lpng libs =- lgd - lm - LZ - ljpeg should you add to libs =- lgd - lpng - LZ - lm- ljpeg .
- On the line that reads LIB_DIRS , replace LIBDIRS =- L. -L/usr/lib/X11 -L/usr/local/lib -L/usr/X11R6/lib become IBDIRS =- L. - L / ( gd -xxx directory ) -L/usr/lib/X11 -/usr/X11R6/lib
- On the line that reads INSTALL_INCLUDE = / usr / local / include replace the directory / usr / local / include directory with - gd xxx
# MakeFor other distributions , please refer to the index.html file located in the directory -xxx gd
# make install
Configuring PHP Birthdays
After two additional packages , you must reconfigure your PHP as follows :
# cd [ your php directory ]Customize direktori_gd and direktori_jpeg - 6b with the directory where you install these two libraries . After re- configured PHP , you can use the function phpinfo () to see if the reconfiguration was successful and saw the types of images are supported.
# . / configure - with- apxs - with- gd = direktori_gd - with- jpeg - dir = direktori_jpeg - 6b
# Make
# make install
To note , you can do so at the top when you first install PHP from source code , not from rpmnya .
For Windows users, generally drawing ability of PHP can be obtained simply by removing the sign ; ( uncoment ) in front of extension = php_gd.dll statement in php.ini file . And this can only be done when you installed PHP distribution package for Windows, complete , not from the installer . I was often advised not to edit the php.ini file , but this time it had to be done so that your PHP has the ability to draw. If later you want to upload your application to a web server, first check whether it has a web server with PHP support for the drawing . Again you can use the function phpinfo () to check.
Now, after a variety of devices have been required to install, then PHP can now be used for drawing. To be able to draw with PHP , you should be familiar with the image functions in PHP . PHP provides several functions that are used to " draw " , either to create a drawing lines, curves , fonts , colors , and others . Before drawing function is used , first the script must send a header that tells the image format that will be created . To use the function of sending a header header () as follows :
Header ( " Content-Type : image / format " )With the format is the format of images to be produced. Supported formats include gif , jpeg , png , and WBMP . Especially for WBMP format , content content-type that should be written is the image / vnd.wap.wbmp .
drawing functions include:
ImageCreate function ( )
This function is a function of the first to be started in creating an image. The syntax is as follows :
$ img = Imagecreate ( x , y )Parameters x and y is an integer that states the size width and height of image in pixels, while $ img is a variable that stores the value. This function can be thought of as functions that prepare the canvas with a size of x times y. The variable $ img henceforth be used as parameters in subsequent functions .
ImageColorAllocate function ( )
This function is a function that allocates a color and save them into a variable . The syntax is as follows :
$ color = ImageColorAllocate ( $ img , r , g , b )The parameters r , g , and b is an integer with a range of values 0 to 255 that indicate a composition of colors in RGB format (Red Green Blue) . The smaller the value, the darker the color. Thus , the composition of color 0 , 0 , 0 is black and the color composition 255 , 255 , 255 are white. The variable $ color to then be used as parameters in subsequent functions .
ImageColorDeAllocate function ( )
This function is a function that contrasts with ImageColorAllocate function ( ) , or in other words remove a color that has been allocated. The syntax is as follows :
ImageColorDeAllocate ( $ img , $ color )Output Function Figure
There are four functions used to generate the output to the browser in the form of images, namely ImageGIF , ImageJPEG , ImagePNG , and ImageWBMP . Penggunannya depending on the type of image that is supported by PHP version you use. The syntax is as follows :
ImageGIF ( $ img [, filename ] )If the filename parameter is included, then the output is not sent to the browser , but rather into a file named filename .
ImagePNG ( $ img [, filename ] )
ImageWBMP ( $ img [, filename ] )
ImageJPEG ( $ img [, filename [, quality ] ] )
ImageFill function ( )
This function is used to give color to the " canvas " that has been created. The syntax is as follows :
ImageFill ( $ img , x , y , $ color )Parameters x , y are the coordinates of the starting point of staining , with a value of 0.0 is located on the top left .
ImageDestroy function ( )
This function will clear the variables used to store images . The syntax is as follows :
ImageDestroy ( $ img )OK , the basic functions for drawing has been given. In the next article we will learn more by studying the functions that are used to produce a line drawing , circles, polygons , and others .
0 komentar:
Post a Comment