Home  >  Article  >  Web Front-end  >  Analysis of the differences between php image generation functions_Basic knowledge

Analysis of the differences between php image generation functions_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:47:081140browse

Newbies are confused about the PHP image generation functions imagecreatetruecolor() and imagecreate(). First, let’s take a look at the official explanation of these two functions:
resource imagecreatetruecolor ( int $x_size , int $y_size )
Returns an image identifier representing a black image of size x_size and y_size.
resource imagecreate (int $x_size, int $y_size)
Returns an image identifier, representing an image of size
There are some differences between the two when changing the background color:
imagecreatetruecolor needs to use imagefill() to fill the color
imagecreate() needs to use imagecolorAllocate() to add the background color
The php case is as follows:

Copy code The code is as follows:

$img = imagecreatetruecolor(100,100); //Create true color image resources
$color = imagecolorAllocate($img,200,200,200); //Assign a gray
imagefill($img,0,0,$color); // Fill the gray
header('content-type: starting from the upper left corner) image/jpeg'); //jpg format
imagejpeg($img); //Display gray squares
?>

Copy code The code is as follows:

$img = imagecreate(100,100);
imagecolorallocate($img,200,200,200) ;
header('content-type:image/jpeg');
imagejpeg($img);
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn