PHP Create image Instance _php Tutorial

Source: Internet
Author: User
Use Imagecreate () to create a variable that represents a blank image, which requires an image-size parameter in pixels, in the format imagecreate (X_size, y_size). If you want to create an image with a size of 250x250, you can use the following statement:

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

Use Imagecreate () to create a variable that represents a blank image, which requires an image-size parameter in pixels, in the format imagecreate (X_size, y_size). If you want to create an image with a size of 250x250, you can use the following statement:

$newimg = imagecreate (250,250);

 

Because the image is still blank, you might want to fill it with some color. You need to first use the Imagecolorallocate () function to specify a name for this color with its RGB value, which is formatted as imagecolorallocate ([image], [red], [green], [blue]). If you want to define azure, you can use the following statement:

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

 

Next, you need to fill this image with this color using the Imagefill () function, which has several versions of the Imagefill () function, such as Imagefillrectangle (), Imagefillpolygon (), and so on. For the sake of 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 established, release the image handle and the memory that is occupied:

 

Imagepng ($NEWIMG);

Imagedestroy ($newimg);? >

In this way, all the code for creating the image looks like this:

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);

? >

http://www.bkjia.com/PHPjc/633012.html www.bkjia.com true http://www.bkjia.com/PHPjc/633012.html techarticle use Imagecreate () to create a variable that represents a blank image, which requires an image-size parameter in pixels, in the format imagecreate (X_size, y_size). If you want to create a ...

  • 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.