Php drawing skills how to load external images

Source: Internet
Author: User
Tags image identifier
Php drawing skills how to load external images

  1. // 1. create a canvas

  2. $ Im = imagecreatetruecolor (300,200); // create a real-color image. the default background is black and the image identifier is returned. Another function, imagecreate, is not recommended.

  3. // 2. load external images

  4. $ Im_new = imagecreatefromjpeg ("baidu.jpg"); // returns the image identifier.
  5. $ Im_new_info = getimagesize ("baidu.jpg"); // get the image size and return an array. This function does not need to use 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 from the outside
  11. (): Place the loaded image in the upper left corner of the canvas.
  12. (0, 0): indicates the position of the loaded image. (0, 0) indicates the starting point in the upper left corner. you can also load only a part of the image.
  13. (*, *): It is represented by *. it can be the width and height of the original image, or it can be smaller than the width and height. only part of the image is intercepted. it is used with the preceding coordinates to represent the intercepted part.
  14. */Bbs.it-home.org
  15. Imagecopy ($ im, $ im_new, 30, 30, $ im_new_info [0], $ im_new_info [1]); // return a Boolean value

  16. // 3. output image

  17. Header ("content-type: image/png ");
  18. Imagepng ($ im); // output to the page. If the second parameter [, $ filename] exists, the image is saved.

  19. // 4. destroy images and release memory

  20. Imagedestroy ($ im );
  21. ?>

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.