Home > Backend Development > PHP Tutorial > Create image instance in php_PHP tutorial

Create image instance in php_PHP tutorial

WBOY
Release: 2016-07-13 10:45:23
Original
717 people have browsed it

Use ImageCreate() to create a variable representing a blank image. This function requires a parameter of the image size in pixels, and its format is ImageCreate(x_size, y_size). If you want to create an image with a size of 250×250, you can use the following statement: ​

<? header ("content-type: image/png"); ​

Use imagecreate() to create a variable representing a blank image. This function requires a parameter of the image size in pixels. Its format is imagecreate(x_size, y_size). If you want to create an image with a size of 250×250, you can use the following statement:

$newimg = imagecreate(250,250);

Since the image is still blank, you may want to fill it with some color. You need to first assign a name to this color using its rgb value using the imagecolorallocate() function. The format of this function is imagecolorallocate([image], [red], [green], [blue]). If you want to define sky blue, you can use the following statement:

$skyblue = imagecolorallocate($newimg,136,193,255);

Next, you need to use the imagefill() function to fill the image with this color. The imagefill() function has several versions, such as imagefillrectangle(), imagefillpolygon(), etc. For simplicity, we use the imagefill() function in the following format:

Imagefill([image], [start x point], [start y point], [color])

imagefill($newimg,0,0,$skyblue);

Finally, release the image handle and the memory occupied after the image is created:

imagepng($newimg);

imagedestroy($newimg); ?>

In this way, the entire code to create the image is as follows:

PHP tutorial code:

<? header ("content-type: image/png");

$newimg = imagecreate(250,250);

$skyblue = imagecolorallocate($newimg,136,193,255);

imagefill($newimg,0,0,$skyblue);

imagepng($newimg);

imagedestroy($newimg);

 ?> 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633012.htmlTechArticleUse ImageCreate() to create a variable representing a blank image. This function requires a parameter of the image size in pixels. , its format is ImageCreate(x_size, y_size). If you want to create a...
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