首页 > Web开发 > 详细

php gd库

时间:2015-12-14 18:12:40      阅读:192      评论:0      收藏:0      [点我收藏+]

手册网址:http://php.net/manual/zh/ref.image.php

gd 画图:

1:创建一个画布;

$image=resource imagecreatetruecolor ( int $x_size , int $y_size );

2:创建原料;

$color=int imagecolorallocate ( resource $image , int $red , int $green , int $blue );

3:画图;

bool imagefill ( resource $image , int $x , int $y , int $color );

4:保存;

bool imagepng ( resource $image [, string $filename ] );

bool imagegif ( resource $image [, string $filename ] );

5:销毁画布;

bool imagedestroy ( resource $image );

画图流程详解:

1)坐标系的讲解:【4个参数】

  两个点确定一个矩形

  左上角的点+宽度+高度

第一步:创建画布:

  1)可以直接用imagecreatetruecolor 创建画布

  2)也可以直接打开一幅图片做画布

imagecreatefromjpeg(‘文件‘);

第二步:配置颜色:

$red=imagecolorallocate($im,255,0,0);

$blue=imagecolorallocate($im,0,0,255);

/*画线*/

bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )

image

第三步:保存图片

1)imagegif  imagejpeg

2)也可以是图片不保存而直接输出【在验证码里比较实用】

此时会输出到浏览器,但是我们必须要告诉浏览器是什么格式的:

header(‘Content-type: image/png‘);

bool imagepng ( resource $image [, string $filename ] );第二个参数不需要

 

php gd库

原文:http://www.cnblogs.com/yanran/p/5031472.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!