Home  >  Article  >  Backend Development  >  php绘图之加载外部图片的方法_php技巧

php绘图之加载外部图片的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:25:001298browse

本文实例讲述了php绘图之加载外部图片的方法。分享给大家供大家参考。具体实现方法如下:

在实际应用中,就是常见的水印功能。

复制代码 代码如下:
//1、创建画布
$im = imagecreatetruecolor(300,200);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。
//2、加载外部图片
$im_new = imagecreatefromjpeg("baidu.jpg");//返回图像标识符
$im_new_info = getimagesize("baidu.jpg");//取得图像大小,返回一个数组。该函数不需要用到gd库。
/*----
****3、将加载的图片,复制到画布上
****参数说明:
 $im:不用说,指的是画布;
 $im_new:源图片,也就是从外面加载进来的图像
 (30,30):将加载进来的图像,放在画布中的位置,左上角
 (0,0):表示加载的图片,从什么位置开始。(0,0)表示左上角起点,也可以只加载图片的一部分进来的
 (*,*):用*表示,可以为原图片宽和高,也可以小于宽高,只截取一部分,与上面坐标一起使用,表示截取的部分
******/
imagecopy($im,$im_new,30,30,0,0,$im_new_info[0],$im_new_info[1]);//返回布尔值
//3、输出图像
header("content-type: image/png");
imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像
//4、销毁图像,释放内存
imagedestroy($im);
?>

希望本文所述对大家的php程序设计有所帮助。

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