All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
DOTNET:LINQ与ADO.NET,3.0的创新_.net资料_编程技术
ASP.NET上传大于4M的文件的相关设置_[Asp.Net教程]
visual c++中的类模板
ASP.NET,2.0的导航控件treeview和menu的实例_.net资料_编程技术
按比例微缩图片的一段小小的JS代码_JavaScript技术_编程技术
ASP.NET的基本编程习惯_[Asp.Net教程]
Asp.net与SQL一起打包部署安装_[Asp.Net教程]
ASP.NET中为DataGrid添加单选框_[Asp.Net教程]
C#中GDI+变形的矩阵表示形式
delphi类的封装
Reading number is top 10 pictures
运动的范冰冰1
Beautiful Japanese beauty(漂亮的日本美女)2
八个盛产美女的国家2
Beautiful Japanese beauty(漂亮的日本美女)
The little woman's bright wire3
Go to the national museum2
yy365网站上的美女2
西方气质的东方美女3
到南昌西站了1
美奂绝伦的风景
Download software ranking
Unix video tutorial9
The cock of the Grosvenor LTD handsome
Tram sex maniac 2 (H) rar bag4
Tram sex maniac 2 (H) rar bag10
在线棋牌游戏3.05版
SQL2000 For 4IN1
Boxer Classic video1
星际争霸1.08硬盘免安装版
仙剑奇侠传98硬盘WINXP版
Unix video tutorial8
aaa published in(发表于) 2013/12/21 22:38:53 Edit(编辑)
玩转图像函数库—常见图形操作(PHP)_php资料_编程技术

玩转图像函数库—常见图形操作(PHP)_php资料_编程技术

玩转图像函数库—常见图形操作(PHP)_php资料_编程技术-你的首页-uuhomepage.com

我尽量不说大理论,诸如什么是png,自己查解决.

PHP自4.3版本开始,捆绑了自己的GD2库,用户可以自己下载并设置.如果要查看自己的php版本是否支持gd模块(支持JPEG,PNG,WBMP但不再支持GIF),如下方式是一种方法:

if(!function_exists('imagecreate')) {
die('本服务器不支持GD模块');
}

如果不支持的话,如何配置 ? 下载gd模块的dll文件,修改php.ini,重启服务器即可.

以下简称PHP作图为PS.

当您打算 PS的话,应该完成如下如下步骤,这是必经的.

1:创建基本PS对象(我假设为$image),填充背景(默认黑),以后的全部ps操作都是基于这个背景图像的.
2:在$image上作图.
3:输出这个图像.
4:销毁对象,清除使用内存.

首先,我们来认识几个常用的函数,这些函数在php手册里面都有详细介绍,此处大体引用下.

resource imagecreate ( int x_size, int y_size )
imagecreate() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的空白图像。
此函数基本同imagetruecolor($width,$height).

int imagecolorallocate ( resource image, int red, int green, int blue )
imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。image 参数是 imagecreatetruecolor() 函数的返回值。red,green 和 blue 分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF。imagecolorallocate() 必须被调用以创建每一种用在 image 所代表的图像中的颜色。

bool imagefill ( resource image, int x, int y, int color )
imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。


bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imageline() 用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)画一条线段。

bool imagestring ( resource image, int font, int x, int y, string s, int col )
imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。如果 font 是 1,2,3,4 或 5,则使用内置字体。

array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
本函数比较重要,参数较多,此处不再列出,它主要是写字到图像上,和上面的函数类似,但必前者强大.

bool imagefilltoborder ( resource image, int x, int y, int border, int color )
imagefilltoborder() 从 x,y(图像左上角为 0, 0)点开始用 color 颜色执行区域填充,直到碰到颜色为 border 的边界为止。【注:边界内的所有颜色都会被填充。如果指定的边界色和该点颜色相同,则没有填充。如果图像中没有该边界色,则整幅图像都会被填充。】

bool imagefilledellipse ( resource image, int cx, int cy, int w, int h, int color )
imagefilledellipse() 在 image 所代表的图像中以 cx,cy(图像左上角为 0, 0)为中心画一个椭圆。w 和 h 分别指定了椭圆的宽和高。椭圆用 color 颜色填充。如果成功则返回 TRUE,失败则返回 FALSE。

输出图像数据:imagepng($image[,$filename])

例一:输出蓝色背景和交叉白线的图形



$width=35;
$height=35;
//创建对象
$image=imagecreate($width,$height);
//提取颜色
$color_white=imagecolorallocate($image,255,255,255);//白色
$color_blue=imagecolorallocate($image,0,0,108);//蓝色
imagefill($image,0,0,$color_blue);
//作图
//线宽
imagesetthickness($image,3);
imageline($image,0,0,$width,$height ,$color_white);
imageline($image,$width,0,0,$height ,$color_white);

//发送对象至头
header('content-type:image/png');
imagepng($image);
/*
//发送对象至文件
$filename="ex1.png";
imagepng($image,$filename);
*/
//销毁对象
imagedestroy($image);
?>


输出图象:玩转图像函数库—常见图形操作(PHP)

在线演示: http://www.phzzy.org/temp/5do8/ex1.php

例二: 阴阳图


$width=400;
$height=400;
$image=imagecreatetruecolor($width,$height);
//提取颜色
$color_black=imagecolorallocate($image,0,2,0);//
$color_white=imagecolorallocate($image,255,255,255);//白色
$color_blue=imagecolorallocate($image,0,0,108);//蓝色
$color_red=imagecolorallocate($image,151,0,4);//红色
$color_my=imagecolorallocate($image,192,192,255);//背景
$color_temp=imagecolorallocate($image,199,199,199);//背景
//作图
imagefill($image,0,0,$color_white);

//第一个是大圆
imagefilledarc ($image,$width/2,$height/2,$height,$height,0,360,$color_blue,img_ARC_PIE);
//两个小圆
imagefilledellipse ($image,$width/2,$height/4 ,$height/2,$height/2,$color_red);
imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$color_blue);
/*imagefilledellipse -- 画一椭圆并填充*/
imagefilledarc ($image,$width/2,$height/2,$height,$height,-90,90,$color_red,img_ARC_PIE);
imagefilledellipse ($image,$width/2,$height/4 * 3,$height/2,$height/2,$color_blue);
//发送对象至头
header('content-type:image/png');
imagepng($image);
/*
//发送对象至文件
$filename="ex1.png";
imagepng($image,$filename);
*/
//销毁对象
imagedestroy($image);
?>


玩转图像函数库—常见图形操作(PHP)

演示: http://www.phzzy.org/temp/5do8/ex2.php

例三:3D图像--cool


$width=400;
$height=400;
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
imagefill($image,0,0,$white);

// make the 3D effect
for ($i = $height /2 +20; $i > $height /2; $i--) {
imagefilledarc($image, $width/2, $i, $width/2, $height /2, 0, 45, $darknavy, img_ARC_PIE);
imagefilledarc($image, $width/2, $i, $width/2, $height /2, 45, 75 , $darkgray, img_ARC_PIE);
imagefilledarc($image, $width/2, $i, $width/2, $height /2, 75, 360 , $darkred, img_ARC_PIE);
}

imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 0, 45, $navy, img_ARC_PIE);
imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 45, 75 , $gray, img_ARC_PIE);
imagefilledarc($image, $width/2, $height /2, $width/2, $height /2, 75, 360 , $red, img_ARC_PIE);


// flush image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
/*
//发送对象至文件
$filename="ex1.png";
imagepng($image,$filename);
*/

?>


玩转图像函数库—常见图形操作(PHP)

演示: http://www.phzzy.org/temp/5do8/ex3.php




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.