Home  >  Article  >  Backend Development  >  How to create images based on php gd library

How to create images based on php gd library

WBOY
WBOYOriginal
2016-07-25 08:55:051183browse
  1. $im = imagecreate(200,150);
  2. echo $im;
  3. ?>
  4. //Output
  5. Resource id #1
Copy code

Second, imagecreatetruecolor - Create a true color canvas 1. Format: imagecreatetruecolor (int x_size, int y_size) 2. Analysis: Like imagecreate, create a blank canvas. The difference is that the canvas created by this function supports more colors, so the effect is better. Pass in the pixel values ​​​​of the width and height of the canvas, and return the pixel values ​​assigned to this by the system. The id number of the block canvas, for example:

  1. $im = imagecreatetruecolor(200,150);
  2. echo $im;
  3. ?>
  4. //Output
  5. Resource id #2
Copy code

Three, imagecreatefromgif - Create A canvas and read a gif format picture into this canvas 1. Format: imagecreatefromgif (string filename) 2. Analysis: The parameter passed in is the file name (plus path) of a gif image. If the image is in other formats, an error will be reported. What is returned is the ID number assigned to this canvas by the system, which can be used for other drawings. Function calls, for example:

  1. $im = imagecreatefromgif('gd_image/gif.gif');
  2. echo $im;
  3. ?>
  4. //Output
  5. Resource id #3
Copy code

Four, imagecreatefromjpeg - Create a canvas and read a jpg format image into the canvas 1. Format: imagecreatefromjpeg (string filename) 2. Analysis: The parameter passed in is the file name of a jpg picture (plus path). If the picture is in other formats, an error will be reported. What is returned is the ID number assigned to this canvas by the system, which can be used for other drawings. Function calls, for example:

  1. $im = imagecreatefromjpeg('gd_image/gif.jpg');
  2. echo $im;
  3. ?>
  4. //Output
  5. Resource id #4
Copy code

Five, imagecreatefrompng - Create a canvas and read a png format picture into this canvas 1. Format: imagecreatefrompng (string filename) 2. Analysis: The parameter passed in is the file name of a png picture (plus path). If the picture is in other formats, an error will be reported. What is returned is the ID number assigned to this canvas by the system, which can be used for other drawings. Function calls, for example:

  1. $im = imagecreatefromgif('gd_image/gif.gif');
  2. echo $im;
  3. ?>
  4. //Output
  5. Resource id #4
Copy code


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