3.1 创建一个画布:
imagecreate(宽,高)--创建一个基于256色的画布
imagecreatetruecolor( int x_size, int y_size ) -- 新建一个真彩色图像
//还有基于某个图片的画布
imagecreatefromgif( string filename )
imagecreatefrompng( string filename )
imagecreatefromjpeg( string filename )
3.2 绘画:
//分配定义颜色
$red = imagecolorallocate($im,255,0,0); //分配一个颜色
//填充背景
bool imagefill(resource image,int x,int y, int color ); //填充背景
//画点
bool imagesetpixel(resource image,int x,int y,int color );//画一个像素点
//画一个线段的函数
bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
//画矩形框(不填充)
bool imagerectangle ( resource image, int x1, int y1, int x2, int y2, int color )
//画矩形框(填充)
bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color )
//绘制多边形
bool imagepolygon ( resource image, array points, int num_points, int color )
bool imagefilledpolygon ( resource image, array points, int num_points, int color )
//绘制椭圆(正圆)
imageellipse ( resource image, int cx, int cy, int w, int h, int color )
imagefilledellipse ( resource image, int cx, int cy, int w, int h, int color )
//绘制圆弧(可填充)
imagearc ( resource image, int cx, int cy, int w, int h, int s, int e, int color)
imagefilledarc ( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
//绘制字串
bool imagestring ( resource image, int font, int x, int y, string s, int col )
bool imagestringup ( resource image, int font, int x, int y, string s, int col )
//绘制文本:
*array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
当上面的字体出现乱码时,使用下面的函数转换编码
string iconv ( string in_charset, string out_charset, string str )
$name="张三";
$str = iconv("ISO8859-1","UTF-8",$name);
$str = iconv("GBK","UTF-8",$name);
$str = iconv("GB2312","UTF-8",$name);
//图片的裁剪、合成、缩放
**bool imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
* imagesx — 取得图像宽度
* imagesy — 取得图像高度
* array getimagesize ( string $filename [, array &$imageinfo ] ) 取得图像大小
3.3.输出图
header("Content-Type: image/jpeg");//设置响应头信息为一个jpeg的图片
imagejpeg($im);//输出一个jpeg图片
header("Content-Type: image/png");//设置响应头信息为一个png的图片
imagepng($im);//输出一个png图片
//输出到指定文件中(另存为)
imagepng($im,"**.png");
3.4.销毁
imagedestroy($im);