(Advanced) PHP image processing technology-GD Library details. if you need it, refer to section 1. start GD extension.
Extension = php_gd2.dll
Apache restart
2. example:
Scenario:
Create a green image of 500x300
① Create a canvas
Canvas, a type of resource-based data. Operational image resources.
Create a canvas (new)
ImageCreate (width and height) to create a canvas based on the color palette.
ImageCreateTrueColor (width, height); create a true color canvas.
Create a canvas (open) based on the image)
ImageCreateFromJPEG (image address );
ImageCreateFromPNG (image address );
ImageCreateFromGIF (image address );
② Operating canvas
Assign color: If you need to use a color on the canvas, you should first assign the color to the canvas.
Function:
Color id = imageColorAllocate (canvas, R, G, B );
Color representation:
RGB
③ Fill the canvas: fill (replace) the filled points that are continuous and of the same color)
Function:
ImageFill (canvas, fill position x, fill position Y, color logo) complete
Coordinates are used for location management:
Origin: 0, 0, the upper left corner of the canvas.
To the right, the X axis increases, and the downward Y axis increases.
Coordinates in the lower right corner: width-1, height-1
④ Output canvas
Output the processed image information in the canvas.
Typical:
1. output to the image file.
2. direct output.
Function:
ImagePNG (canvas [, file address]):
ImageJPEG ();
ImageGIF ();
If there is no second parameter, it indicates direct output.
Note: If it is directly output to the browser, you need to inform the browser that the response data type should be in PNG format:
Use the command Content-type;
A canvas can be output multiple times and in various formats
⑤ Destroy canvas resources
ImageDestroy ()
Sample code:
Sample code:
The above is (Advanced article) PHP image processing technology-the content of the GD Library. For more information, see PHP Chinese network (www.php1.cn )!