Differences between php image generation functions

Source: Internet
Author: User

New users are puzzled by the imagecreatetruecolor () and imagecreate () functions of php Image Generation. First, let's take a look at the official explanations of these two functions:
Resource imagecreatetruecolor (int $ x_size, int $ y_size)
Returns an image identifier, representing a black image of x_size and y_size.
Resource imagecreate (int $ x_size, int $ y_size)
Returns an image identifier, representing the size of an image.
The two have some differences when changing the background color.:
Imagecreatetruecolor must be filled with imagefill ()
Imagecreate () needs to use imagecolorAllocate () to add the background color
The php case is as follows::

Copy codeThe Code is as follows: <? Php
$ Img = imagecreatetruecolor (100,100); // create a true color image resource
$ Color = imagecolorAllocate ($ img, 200,200,200); // assign a gray color.
Imagefill ($ img, $ color); // fill in the gray from the upper left corner
Header ('content-type: image/jpeg '); // jpg format
Imagejpeg ($ img); // shows the gray square
?>

Copy codeThe Code is as follows: <? Php
$ Img = imagecreate (100,100 );
Imagecolorallocate ($ img, 200,200,200 );
Header ('content-type: image/jpeg ');
Imagejpeg ($ img );
?>

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.