Home  >  Article  >  Backend Development  >  How to load external images with php drawing skills

How to load external images with php drawing skills

WBOY
WBOYOriginal
2016-07-25 08:52:12951browse
  1. //1. Create canvas

  2. $im = imagecreatetruecolor(300,200);//Create a new true color image, the default background is black, and return the image identifier. There is also a function imagecreate that has been deprecated.

  3. //2. Load external images

  4. $im_new = imagecreatefromjpeg("baidu.jpg");//Return the image identifier
  5. $im_new_info = getimagesize("baidu.jpg");/ /Get the image size and return an array. This function does not require the use of the gd library.
  6. /*----
  7. ****3. Copy the loaded image to the canvas
  8. ****Parameter description:
  9. $im: Needless to say, it refers to the canvas;
  10. $im_new: source image, That is, the image loaded in from the outside
  11. (30,30): Place the loaded image in the position of the canvas. The upper left corner
  12. (0,0): Indicates where the loaded image starts. (0,0) represents the starting point of the upper left corner. You can also load only a part of the image. (*,*): represented by *, it can be the width and height of the original image, or it can be smaller than the width and height. Only a part of the image is intercepted, and it is the same as the above Used together with coordinates, it represents the intercepted part
  13. ******/bbs.it-home.org
  14. imagecopy($im,$im_new,30,30,0,0,$im_new_info[0],$im_new_info[1 ]);//Return Boolean value

  15. //3. Output image

  16. header("content-type: image/png");
  17. imagepng($im);//Output to page . If there is a second parameter [,$filename], it means saving the image

  18. //4. Destroy the image and release the memory

  19. imagedestroy($im);
  20. ?>
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