Home > Web Front-end > JS Tutorial > body text

Analysis of the differences between php image generation functions_Basic knowledge

WBOY
Release: 2016-05-16 17:47:08
Original
1139 people have browsed it

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);
?>
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!