This article mainly introduces the php plotting method for loading external images, involving the use of imagecopy methods in the GD Library, for more information about how to load external images, see the example in this article. 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.