正 文

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


www.7dspace.com  更新日期:2006-2-13 23:18:01  七度空间


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

<?php
$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);
?>

输出图象:

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

例二: 阴阳图

<?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);
?>

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

例三:3D图像--cool

<?php
$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);
 */

?>

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

2页,页码:[1] [2] 

上一篇:浏览器能弥补宋体缺陷?
下一篇:聊天更轻松 腾讯QQ消息自动发送
标题:玩转图像函数库—常见图形操作 作者:5do8 来源:蓝色理想
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐