Php plotting-external image Loading Method

Source: Internet
Author: User
Tags image identifier imagecopy
This article mainly introduces how to load external images by using php plotting. It involves the use of imagecopy In the GD library. For more information, see

This article mainly introduces how to load external images by using php plotting. It involves the use of imagecopy In the GD library. For more information, see

This article describes how to load external images by using php plotting. Share it with you for your reference. The specific implementation method is as follows:

In practice, it is a common watermark function.

The Code is as follows:

<? Php
// 1. Create a canvas
$ 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.
// 2. Load External Images
$ Im_new = imagecreatefromjpeg ("baidu.jpg"); // returns the image identifier.
$ Im_new_info = getimagesize ("baidu.jpg"); // get the image size and return an array. This function does not need to use the gd library.
/*----
* *** 3. Copy the loaded image to the canvas.
* *** Parameter description:
$ Im: Needless to say, it refers to the canvas;
$ Im_new: source image, that is, the image loaded from the outside
(): Place the loaded image in the upper left corner of the canvas.
(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.
(*, *): 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.
******/
Imagecopy ($ im, $ im_new, 30, 30, $ im_new_info [0], $ im_new_info [1]); // return a Boolean Value
// 3. output image
Header ("content-type: image/png ");
Imagepng ($ im); // output to the page. If the second parameter [, $ filename] exists, the image is saved.
// 4. Destroy images and release memory
Imagedestroy ($ im );
?>

I hope this article will help you with php programming.

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.