Detailed description of creating images and colors and filling background colors (PHP graphic image typical application tutorial 1)

Source: Internet
Author: User
Tags image identifier
If there are not a variety of graphic images on the webpage, there is always a lack of anger. beautiful graphic images make the entire webpage look more attractive and make the ideas that are hard to express in many words clear at a glance, in addition, the relationship before data can be clearly expressed. Next we will explain various technologies of graph image processing in PHP! Detailed description of creating images and colors and filling background colors (PHP graphic image typical application tutorial 1)

If there are not a variety of graphic images on the webpage, there is always a lack of anger. beautiful graphic images make the entire webpage look more attractive and make the ideas that are hard to express in many words clear at a glance, in addition, the relationship before data can be clearly expressed. Next we will explain various technologies of graph image processing in PHP!

In the previous article, what is the GD database? This section describes how to install and activate the GD Library in PHP. we will introduce how to create images, create colors, and fill the background color!

1. create an image

You can use the GD2 function library to process various graphics and images. Creating a canvas is the first step to use the GD2 function library to create images. no matter what images you create, you must first create a canvas, other operations are completed on the canvas. First, create an image of the specified size with a black background color. use the imagecreatetruecolor () function. the syntax format of this function is as follows:

resource imagecreatetruecolor ( int $width , int $height )

Imagecreatetruecolor () returns an image identifier, representing a black image of x_size and y_size.

The following code introduces this function only by using an instance:

 

It is described as follows:

The header is used to inform the browser: Although the request is a file with the. php suffix, the returned file is not HTML but a PNG image.

Imagepng is used to output the generated image to the browser in PNG format.

Imagedestroy is used to release the created image resources.

If you call the generated image, you can directly call the image generated by php as an image.

The page output result is as follows:

This canvas is complete!

2. create a color

To create a color, we need to use the imagecolorallocate () function. First, let's look at the syntax format of this function:

int imagecolorallocate ( resource $image , int $red , int $green , int $blue )

The first call to imagecolorallocate () will fill the background color of the image based on the color palette. each subsequent call will only create a color to call other functions. for example, call the imagefill function, to color the canvas!

The following example is used to describe in detail. the specific code is as follows:

 

The page output result is as follows:

3. create an image and fill in the background color

After creating the image and creating the color, we can complete these two steps. we need to use the imagecreate () function. let's first look at the syntax format of this function:

resource imagecreate ( int $x_size , int $y_size )

Imagecreate () returns an image identifier, representing a blank image of x_size and y_size. Fill in the background color when creating an image in ps!

The following example is used to describe in detail. the specific code is as follows:

 

The page output result is:

This article introduces how to create images and colors. I believe all of you have mastered this. next we will introduce how to add text to images, for more information, see how to add text to images using the GD2 function (PHP graphic image typical application tutorial 2).

The preceding section describes how to create images, colors, and fill background colors (PHP graphic image typical application tutorial 1). For more information, see other related articles in the first PHP community!

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.