Home > Backend Development > PHP Tutorial > Play with image function library—common graphics operations_PHP tutorial

Play with image function library—common graphics operations_PHP tutorial

WBOY
Release: 2016-07-21 16:12:22
Original
848 people have browsed it

I try not to talk about big theories, such as what png is, find it yourself.

Since version 4.3, PHP has bundled its own GD2 library, which users can download and set up by themselves. If you want to check whether your PHP version supports the gd module (supports JPEG, PNG, WBMP but no longer supports GIF), do the following: It’s a method:

if(!function_exists('imagecreate')) {
die('This server does not support GD module');
}

If it is not supported, how to configure it? Download the dll file of the gd module, modify php.ini, and restart the server.

Hereinafter referred to as PHP drawing is PS.

When you plan to PS, you should complete the following steps, which are necessary.

1: Create a basic PS object (I assume it is $image), fill in the background (black by default), all subsequent PS operations are based on this background image.
2: Draw on $image.
3: Output this image.
4: Destroy the object and clear the used memory.

First of all, let’s get to know a few commonly used functions. These functions are introduced in detail in the PHP manual and are generally quoted here.

resource imagecreate ( int x_size, int y_size )
imagecreate() returns an image identifier representing a blank image of size 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 representing the color composed of the given RGB components. 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 respectively. These parameters are integers from 0 to 255 or hexadecimal 0x00 to 0xFF. imagecolorallocate() must be called to create each color used in the image represented by image.

bool imagefill (resource image, int x, int y, int color)
imagefill() performs area filling with the color color at the coordinates x, y of the image image (the upper left corner of the image is 0, 0) (i.e. Points with the same color as the x, y point and adjacent points will be filled).


bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imageline() uses color color in the image image from coordinates x1, y1 to x2, y2 ( Draw a line segment with the upper left corner of the image at 0, 0).

bool imagestring (resource image, int font, int x, int y, string s, int col)
imagestring() uses col color to draw string s to the x, y coordinates of the image represented by image (This is the coordinate of the upper left corner of the string, and the upper left corner of the entire 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 and has many parameters, which will not be listed here. It is mainly used to write text to images, similar to the above function, but more powerful than the former.

bool imagefilltoborder (resource image, int x, int y, int border, int color)
imagefilltoborder() starts from x, y (the upper left corner of the image is 0, 0) point and performs area filling with color color until Until it reaches the border with color border. [Note: All colors within the border will be filled. If the specified border color is the same as the point, there is no fill. If the border color is not present in the image, the entire image will be filled. 】

bool imagefilledellipse (resource image, int cx, int cy, int w, int h, int color)
imagefilledellipse() uses cx, cy in the image represented by image (the upper left corner of the image is 0, 0) Draw an ellipse for the center. w and h specify the width and height of the ellipse respectively. The ellipse is filled with color. Returns TRUE on success, FALSE on failure.

Output image data: imagepng($image[,$filename])

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313722.htmlTechArticleI try not to talk about big theories, such as what is png, check it out yourself. PHP has been bundled since version 4.3 Users can download and set up their own GD2 library. If you want to check whether your php version supports...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template