Home > Backend Development > PHP Tutorial > PHP graphics processing tutorial-php generate pictures (1/4)_PHP tutorial

PHP graphics processing tutorial-php generate pictures (1/4)_PHP tutorial

WBOY
Release: 2016-07-13 10:45:18
Original
776 people have browsed it

The function of generating pictures is often used in web applications. Creating pictures in PHP tutorials requires the support of the gd library to create graphics. With this graphics function, we can easily generate thumbnails. Verification code, watermarking pictures, etc.

In order to run the image creation function normally, you need to install the gd library in php. The method is as follows. In the win system, find php.ini

;The ";" in front of extension=php_gd2.dll is gone. Restart apache and it will be OK.

Let’s take a look at an example

PHP’s gd library can generate a variety of image files, such as gif, png, jpg, wbmp, xpm, etc. Let’s look at a file that generates a square.

$height = 300;
$width = 300;
//Create background image
$im = ImageCreateTrueColor($width, $height);
//Assign color
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
//Draw color to image
ImageFill($im, 0, 0, $blue);
//Draw string: Hello,PHP
ImageString($im, 10, 100, 120, 'Hello,PHP', $white);
//Output image, define header
Header ('Content-type: image/png');
//Send image to browser
ImagePng($im);
//Clear resources
ImageDestroy($im);
?>

To view the results, just browse the php file. If you want an image, call

Example 2, using basic functions to create images imagecreate()

resource imagescreate(int x,inty)

imagedestroy is the memory space occupied by the image

int ingaedestroy(image)

imagecopy()

int imagecopy(dst_im,sr_im,int x,int y,int x,int y,)

1 2 3 4

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633047.htmlTechArticleThe function of generating images is often used in web applications. Creating images in PHP tutorials requires the gd library Only with support can we create graphics. With this graphics function, we can easily generate...
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