Similarities and differences between imagecreatetruecolor () and imagecreate ()

Source: Internet
Author: User

Common feature: both functions are used to create a canvas.

Differences:

1. The process of creating a canvas and filling the canvas with colors is different;

Imagecreatetruecolor (int x, int Y) is used to create an image of X and Y (black by default ), to change the background color, you need to assign the canvas color imagecolorallcollate (Resource: image, Red: int, Green: int, Blue: INT), and then fill the canvas with the color function imagefill (Resource: image, int X, int y, $ color );

Code:

<? PHP

// Set the file type to image
Header ('content-type: image/PNG ');

// Create a canvas
$ Image = imagecreatetruecolor (200,200 );

// Assign color to the canvas
$ Color = imagecolorallocate ($ image, 174,48, 96 );

// Fill color
Imagefill ($ image, 0, 0, $ color );

// Generate an image
Imagepng ($ image );

// Save the image, generate the image, and save the image in two steps: either generate or save
imagepng($image,‘./1.png‘);
?>

Imagecreate (int x, int Y) is used to create an image with the size of X and Y (no color by default, You need to specify the color ), if you want to change the background color, you need to assign the canvas color imagecolorallcollate (Resource: image, Red: int, Green: int, Blue: INT). Unlike the above, you do not need to fill the canvas, this is because imagecolorallcollate () is automatically filled when the imagecreate () function creates a canvas.

Code:

<? PHP
// Set the file type to image
Header ('content-type: image/PNG ');

// Create a canvas
$ Image = imagecreate (200,200 );

// Assign color to the canvas and fill the canvas
$ Color = imagecolorallocate ($ image, 174,48, 96 );

// Generate an image
Imagepng ($ image );

// Save the image, generate the image, and save the image in two steps: either generate or save
Imgaepng ($ image, './1.png ');
?>

2. Different colors are supported. imagecreatetruecolor () supports more colors.

 

Similarities and differences between imagecreatetruecolor () and imagecreate ()

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.