Functions | graphics
I try not to say big theories, such as what is PNG and find out for myself.
PHP has been bundled with its own GD2 library since version 4.3, and users can download and set it themselves. If you want to see if your PHP version supports the GD module (support for Jpeg,png,wbmp but no longer supports GIF), this is a way to:
if (!function_exists (' imagecreate ')) {
Die (' This server does not support GD module ');
}
If not, how do I configure it? Download the GD module DLL file, modify the php.ini, restart the server.
The following is referred to as PS PHP mapping.
When you intend to PS, you should complete the following steps, which are required.
1: Create the basic PS object (I assumed to be $image), fill the background (the default black), all future PS operations are based on this background image.
2: Drawing on the $image.
3: Output this image.
4: Destroy the object, clear the use of memory.
First, we'll get to know a couple of commonly used functions, which are described in detail in the PHP manual, which is generally referenced here.
Resource imagecreate (int x_size, int y_size)
Imagecreate () returns an image identifier that represents a blank image with a size of x_size and y_size.
This function is basically the same as Imagetruecolor ($width, $height).
int Imagecolorallocate (resource image, int red, int green, int blue)
Imagecolorallocate () returns an identifier that represents a color composed of the given RGB component. The image parameter is the return value of the Imagecreatetruecolor () function. Red,green and Blue are the red, green, and blue components of the desired color. These parameters are integers from 0 to 255 or hexadecimal 0x00 to 0xFF. Imagecolorallocate () must be called to create each color in the image that is represented by images.
BOOL Imagefill (resource image, int x, int y, int color)
Imagefill () performs a region fill with a color color in the coordinate x,y of the image image (0, 0) in the upper-left corner (that is, the same color as the x, Y point, and adjacent points are filled).
BOOL Imageline (resource image, int x1, int y1, int x2, int y2, int color)
Imageline () Draws a line segment from the coordinate x1,y1 to the x2,y2 (0, 0) in image images in color color.
BOOL Imagestring (resource image, int font, int x, int y, string s, int col)
Imagestring () uses the Col color to draw the string s to the x,y coordinates of the image it represents (this is the upper-left coordinate of the string and the upper-left corner of the image is 0,0). If font is 1,2,3,4 or 5, the built-in font is used.
Array Imagettftext (resource image, float size, float angle, int x, int y, int color, string fontfile, string text)
This function is more important, more parameters, no longer listed here, it is mainly written to the image, and the above function similar, but the former strong.
BOOL Imagefilltoborder (resource image, int x, int y, int border, int color)
Imagefilltoborder () starts the area fill with a color color from the x,y (0, 0) point in the upper-left corner of the image until it touches the boundary of the border. "Note: All colors within the boundary will be filled." If the specified boundary color is the same as the point color, there is no padding. If the boundary color is not in the image, the entire image is populated. 】
BOOL Imagefilledellipse (resource image, int cx, int cy, int w, int h, int color)
Imagefilledellipse () draws an ellipse at the center of the image represented by Cx,cy (0, 0 in the upper-left corner of the image). W and H Specify the width and height of the ellipse respectively. The ellipse is filled with a color color. Returns TRUE if successful, and returns FALSE if it fails.
Output image data: Imagepng ($image [, $filename])
Example one: Output blue background and crossed white line graphics
<?php
$width = 35;
$height = 35;
Creating objects
$image =imagecreate ($width, $height);
Extract Color
$color _white=imagecolorallocate ($image, 255,255,255);//White
$color _blue=imagecolorallocate ($image, 0,0,108);//Blue
Imagefill ($image, 0,0, $color _blue);
Drawing
Line width
Imagesetthickness ($image, 3);
Imageline ($image, 0,0, $width, $height, $color _white);
Imageline ($image, $width, 0,0, $height, $color _white);
Send object to Header
Header (' content-type:image/png ');
Imagepng ($image);
/*
Send object to File
$filename = "Ex1.png";
Imagepng ($image, $filename);
*/
Destroying objects
Imagedestroy ($image);
?>
Output Image:
Online Demo: http://www.phzzy.org/temp/5do8/ex1.php
[1] [2] [3] Next page