1. Enable GD extension
extension=php_gd2.dll
Apache restart
2. Example:
Scenario:
Make a 500×300 green picture
①Create canvas
Canvas, a kind of resource data. Image resources that can be manipulated.
Create a new canvas (new)
ImageCreate(width, height), create a canvas based on the palette.
imageCreateTrueColor(width, height); Create a true color canvas.
Create canvas based on image (open)
imageCreateFromJPEG(image address);
imageCreateFromPNG(image address);
imageCreateFromGIF(image address);
②Operation canvas
Assign color: If you need to use a certain color on the canvas, you should assign the color to the canvas first.
Use function:
Color identification = imageColorAllocate(canvas, R, G, B);
Color representation:
RGB
③Fill the canvas: Fill (replace) the filling points with consecutive points with the same color
Use the function:
imageFill(canvas, filling position x, filling position Y, color Logo) Complete
The position is managed using coordinates:
Origin: 0, 0, the upper left corner of the canvas.
To the right, the x-axis increases, and down the Y-axis increases.
Coordinates of the lower right corner: width-1, height-1
④Output canvas
Output the processed pattern information in the canvas.
Typical:
1Output to image file.
2Direct output.
Use function:
imagePNG(canvas[, file address]):
imageJPEG();
imageGIF();
If there is no second parameter, it means direct output.
Note: If it is output directly to the browser, you need to inform the browser that the type of response data should be a PNG format image:
Use the command Content-type;
a The canvas can be output multiple times in various formats
⑤Destroy canvas resources
imageDestroy()
Sample code:
Copy after login
Sample code:
Copy after login
The above is the content of (Advanced) PHP image processing technology-GD library. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!