Home  >  Article  >  Backend Development  >  How to load external images in PHP drawing, _PHP tutorial

How to load external images in PHP drawing, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:07984browse

How to load external images in php drawing,

The example in this article describes the method of loading external images in PHP drawing. Share it with everyone for your reference. The specific implementation method is as follows:

In practical applications, it is a common watermark function.

Copy code The code is as follows:
//1. Create canvas
$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.
//2. Load external images
$im_new = imagecreatefromjpeg("baidu.jpg");//Return image identifier
$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.
/*----
****3. Copy the loaded image to the canvas
****Parameter description:
$im: Needless to say, it refers to the canvas;
$im_new: Source image, which is an image loaded from outside
(30,30): Place the loaded image in the canvas, upper left corner
(0,0): Indicates where the loaded image starts. (0,0) represents the starting point of the upper left corner, you can also load only 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 is intercepted and used together with the above coordinates to indicate the intercepted part
******/
imagecopy($im,$im_new,30,30,0,0,$im_new_info[0],$im_new_info[1]);//Return Boolean value
//3. Output image
header("content-type: image/png");
imagepng($im);//Output to the page. If there is a second parameter [,$filename], it means saving the image
//4. Destroy the image and release memory
imagedestroy($im);
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947209.htmlTechArticleHow to load external images in php drawing. This article describes the method of loading external images in php drawing. Share it with everyone for your reference. The specific implementation method is as follows: In practical application...
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