Php: creating image instances _ PHP Tutorial

Source: Internet
Author: User
Php creates an image instance. Use ImageCreate () to create a variable that represents a blank image. this function requires a parameter of the image size in pixels. the format is ImageCreate (x_size, y_size ). If you want to create a variable that represents a blank image using ImageCreate (), this function requires an image size parameter in pixels. the format is ImageCreate (x_size, y_size ). To create an image of 250x250 in size, use the following statement:

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

Use imagecreate () to create a variable that represents a blank image. this function requires a parameter of the image size in pixels. the format is imagecreate (x_size, y_size ). To create an image of 250x250 in size, use the following statement:

$ Newimg = imagecreate (250,250 );

 

Because the image is still blank, you may want to fill it with some color. You must first use the imagecolorallocate () function to specify a name for this color with its rgb value. The format of this function is imagecolorallocate ([image], [red], [green], [blue]). To define the sky blue, 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 () and imagefillpolygon. 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, after the image is created, the image handle and occupied memory are released:

 

Imagepng ($ newimg );

Imagedestroy ($ newimg);?>

The code for creating an 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 );

?>

Fill () creates a variable that represents the blank image. this function requires the parameter of the image size in pixels, in the format of ImageCreate (x_size, y_size ). If you want to create...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.