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