PHP生成3D的百分比图形统计效果

 更新时间:2016年11月25日 16:58  点击:1984
本程序是根据用户提供的数据生成3D效果的百分比图片统计效果有一点像中国站长

$image = imagecreatetruecolor(200,200);  //创建一张200*200的画布;

 代码如下 复制代码

//创建多种又区分的颜色
$red = imagecolorallocate($image,255,0,0);
$blue  = imagecolorallocate($image,0,0,255);
$yellow = imagecolorallocate($image,255,255,0);
$violet = imagecolorallocate($image,255,0,255);
$white = imagecolorallocate($image,255,255,255);
$black = imagecolorallocate($image,0,0,0);


//使用for循环创建3d效果底层效果
for($i=120;$i>100;$i--){
    imagefilledarc($image,100,$i,200,120,0,30,$red,img_arc_pie);//img_arc_pie注释如下:

    imagefilledarc($image,100,$i,200,120,30,80,$blue,img_arc_pie);
    imagefilledarc($image,100,$i,200,120,80,360,$yellow,img_arc_pie);
}
//bool imagefilledarc ( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
//
//imagefilledarc() 在 image 所代表的图像中以 cx,cy(图像左上角为 0, 0)画一椭圆弧。如果成功则返回 true,失败则返回 false。w 和 h 分别指定了椭圆的宽和高,s 和 e 参数以角度指定了起始和结束点。style 可以是下列值按位或(or)后的值:
//
//img_arc_pie
//
//img_arc_chord
//
//img_arc_nofill
//
//img_arc_edged


//这个层是最上面一层的效果,这样立体效果就出来了!
    imagearc($image,100,100,200,120,0,360,$black);//添加一个黑色的边圈,这样3d效果看起来更加明显点
    imagefilledarc($image,100,100,200,120,0,30,$red,img_arc_pie);
    imagefilledarc($image,100,100,200,120,30,80,$blue,img_arc_pie);
    imagefilledarc($image,100,100,200,120,80,360,$yellow,img_arc_pie);

//添加百分比数据,当然此处必要的时候可以批量的进行一定的运算将输入输入到图片上
    $str = iconv ("gbk","utf-8","36%");//如果要输入中文需要此转换。example:占用:30%;
    imagettftext($image,10,360-15,100+70,115,$white,"simhei.ttf",$str);

 

imagejpeg($image);
imagedestroy($image);

 

在用户验证页面,如注册,登录的时候,为了加强用户登录的安全性,添加验证码验证代码,下面我为各位朋友提供一四款不同同类型的php验证代码程序,最后一款是一款使用了验证代码的实例代码。
 代码如下 复制代码
date_default_timezone_set('asia/shanghai');
 function setcode($len)
 {
  $code = '';
  for ($i=0;$i<$len;$i++)//生成随机长度
  {
   $code .= chr(drand());
  }
  return $code;
 }
 //生成一个随机字符
 function drand()
 {
  $rand = mt_rand(0,2);
  $str = '';
  switch ($rand)
  {
   case 0: $str = mt_rand(48,57);break;//数字
   case 1: $str = mt_rand(65,90);break;//大写字母
   case 2: $str = mt_rand(97,122);break;//小写字母
  }
  return $str;
 }
 $_session['checkcode'] = $code = setcode(5);

//php图片验证码原代码,需支持gd2.dll扩展,需修改php.ini后重启iis or ap

 代码如下 复制代码

session_start();
session_register('safecode');
$type = 'gif';
$width= 40;
$height= 16;
header("content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randstr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
     $im = @imagecreatetruecolor($width,$height);
}else{
     $im = @imagecreate($width,$height);
}
     $r = array(225,211,255,223);
     $g = array(225,236,237,215);
     $b = array(225,236,166,125);

     $key = rand(0,3);
 
     $backcolor = imagecolorallocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
     $bordercolor = imagecolorallocate($im, 0, 0, 0);//边框色
     $pointcolor = imagecolorallocate($im, 255, 170, 255);//点颜色

     @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backcolor);//背景位置
     @imagerectangle($im, 0, 0, $width-1, $height-1, $bordercolor); //边框位置
     $stringcolor = imagecolorallocate($im, 255,51,153);

     for($i=0;$i<=100;$i++){
           $pointx = rand(2,$width-2);
           $pointy = rand(2,$height-2);
           @imagesetpixel($im, $pointx, $pointy, $pointcolor);
     }

     @imagestring($im, 3, 5, 1, $randval, $stringcolor);
     $imagefun='image'.$type;
     $imagefun($im);
     @imagedestroy($im);
     $_session['safecode'] = $randval;
//产生随机字符串
function randstr($len=6,$format='all') {
           switch($format) {
                 case 'all':
                 $chars='abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789www.111cn.net'; break;
                 case 'char':
                 $chars='abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; break;
                 case 'number':
                 $chars='0123456789'; break;
                 default :
                 $chars='abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789';
                 break;
           }
     $string="";
     while(strlen($string)<$len)
     $string.=substr($chars,(mt_rand()%strlen($chars)),1);
     return $string;
}

 

//调用此页面,如果下面的式子成立,则生成验证码图片
if($_get["action"]=="verifycode")
{
    rand_create();
}
//验证码图片生成
function rand_create()
{
    //通知浏览器将要输出png图片
    header("content-type: image/png");
    //准备好随机数发生器种子 
    srand((double)microtime()*1000000);
    //准备图片的相关参数  
    $im = imagecreate(62,20);
    $black = imagecolorallocate($im, 0,0,0);  //rgb黑色标识符
    $white = imagecolorallocate($im, 255,255,255); //rgb白色标识符
    $gray = imagecolorallocate($im, 200,200,200); //rgb灰色标识符
    //开始作图    
    imagefill($im,0,0,$gray);
    while(($randval=rand()%100000)<10000);{
        $_session["login_check_num"] = $randval;
        //将四位整数验证码绘入图片 
        imagestring($im, 5, 10, 3, $randval, $black);
    }
    //加入干扰象素   
    for($i=0;$i<200;$i++){
        $randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
        imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
    }
    //输出验证图片
    imagepng($im);
    //销毁图像标识符
    imagedestroy($im);
}
//检验验证码
function rand_check()
{
    if($_post["reg_rand"] == $_session["login_check_num"]){
        return true;
    }
    else{
        exit("验证码输入错误");
    }
}

//验证码通过gd生成png图片,并把$randval随机数字赋给$_session['login_check_num'],在通过用户输入的$_post进行比较,来判断是否正确。达到需要实现的功能,需要修改php.ini文件,使php支持gd库

这是一款经典实用的生成小图的php代码,有专业素语来讲就是php 生成缩略图代码哦。

# 显示图形及连接

 function showdir ($adirectory, $i)

{
  global $browsedir;

  $start = $i;

# 更改 $maxcols 及 $maximages 可改变每一页显示的小图的行数与列数。

  $maxcols = 2;
  $maximages = 6;
  $maximages = $i + ($maximages - 3);

# 更改 $imagemaxwidth 及 $imagemaxheight 可改变显示小图的宽度与高度。

  $imagemaxwidth = 100;
  $imagemaxheight = 100;
   
# 计算高度与宽度的比例。

  $imagemaxratio =  $imagemaxwidth / $imagemaxheight;
   
  $ndirectory = sizeof ($adirectory);
  echo (table_start);
  for ($i; $i<=$maximages;)
  {
     echo (row_start);
     for ($icols=1; $icols<=$maxcols; $icols++)
     {
       echo (col_start);
       $imagefilename = $adirectory[++$i];
       if (strlen($imagefilename)>0)
       {
         $imagepath = $browsedir."/".$imagefilename;
         $imagesize = getimagesize ($imagepath);
         if ($imagesize)
         {
           $imagewidth = $imagesize[0];
           $imageheight = $imagesize[1];
           $imageratio = $imagewidth / $imageheight;
           if ($imageratio > $imagemaxratio)
           {
              $imageoutputwidth = $imagemaxwidth;
              $imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheight);
           }
           else if ($imageratio < $imagemaxratio)
           {
              $imageoutputheight = $imagemaxheight;
              $imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidth);
           } else
           {
              $imageoutputwidth = $imagemaxwidth;
              $imageoutputheight = $imagemaxheight;
           }

# 显示图形

           echo (a_start.$imagepath.a_close);
           echo (img_start.$imagepath.img_width.$imageoutputwidth.img_height.$imageoutputheight.img_end);
           echo (line_break.$adirectory[$i]);
           echo (a_end);
         }
         echo (col_end);
       }
     }
     echo (row_end);
  }
  echo (table_end);
pagemenu ($browsedir, $ndirectory, $start);

}

function pagemenu ($browsedir, $ndirectory, $pg) {

echo "<br><center><font face="verdana, arial, helvetica, sans-serif" size="1" color="#000033">page:";

$pg_num = 1;

for ($img_num = 0; $img_num <= $ndirectory;) {

    if ($pg == $img_num) {
    echo "<span class="menulink_1"><a href="thumb.php?browsedir=$browsedir&start=$img_num"> *$pg_num</a> <span>";
    } else {
    echo "<span class="menulink_2"><a href="thumb.php?browsedir=$browsedir&start=$img_num"> $pg_num</a> <span>";
    }

# 建立其他页次的连接, 每页显示四张图, 故页数 $pg_num 每加 1 , $img_num 就加 4 。

    $pg_num = $pg_num + 1;
    $img_num = $img_num + 4;

}

echo "</font> ";

}

function dirtoarray ($browsedir, $extensions)
{

  $nextensions = sizeof ($extensions);
  $idirectory = 0;
  $directory = dir($browsedir);
   
  while ($entry = $directory->read())
  {
      for ($i=1; $i<=$nextensions; $i++)
      {
         $compare = stristr ($entry, $extensions[$i]);
         if (strlen($compare) == strlen($extensions[$i]))
         {
            $adirectory[++$idirectory] = $entry;
            break;
         }
      }
  }
  $directory->close();
  return $adirectory;
}

#主程序

#变量 $browsedir 为图形文件放置的位置。

$browsedir="./images";

# 允许浏览的图形文件扩展名, 放置於数组中, 可自行增加。

$extensions[1] = "jpeg";
$extensions[2] = "jpg";
$extensions[3] = "gif";
$extensions[4] = "png"; 
showdir (dirtoarray ($browsedir, $extensions), $start);

define ("line_break", "<br>");
define ("table_start", "<table width=600> ");
define ("table_end", "</table> ");
define ("row_start", "  <tr> ");
define ("row_end", "  </tr> ");
define ("col_start", "   <td align=center>       ");
define ("col_end", "    </td> ");
define ("img_start", "<img src=");
define ("img_end", ">");
define ("img_width", " width=");
define ("img_height", " height=");
define ("a_start", '<a href="');
define ("a_close", '">');
define ("a_end", "</a>");
?>

这是一款简单实用的php验证码生成程序了,主要是利用了php gd库来生成图形验证码,并且保存到session中,生成的代码是利用rand随机生成的。
 代码如下 复制代码

session_start();
$im=imagecreatetruecolor(100,30);
//分配颜色
$bg=imagecolorallocate($im,0,0,0);
$textcolor=imagecolorallocate($im,255,255,255);
//在图片上划线
for($i=0;$i<3;$i++){

$te1 = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,0,rand(0,15),100,rand(0,15),$te1);
}
//在图片上打印200个点
for($i=0;$i<200;$i++){

 imagesetpixel($im,rand()%100,rand()%30,$te1);
}
for($i=0;$i<4;$i++){
 //dechex()把十进制转换成十六进制
 $rand.= dechex(rand(1,15));
}
$_session[check_pic]=$rand;
imagestring($im,5,rand(3,70),rand(3,15),$rand,$textcolor);
header("content-type:image/jpeg");
imagejpeg($im);

/*
生成验证的作用是防止用户乱注册了,这是一等的验证程序
*/

这款php图片生成教程是一款从生成一个简单的图像到生成复杂的图形的php教程,下面就来看简单到复杂有12个生成图像实例。

1 生成一个简单图像。
2 设定图像的颜色。
3 在图像上绘制直线。
4 在图像上显示文字。
5 在图像中显示中文字符。
6 打开已存在的图片。
7 获取图片的相关属性。
8 函数getimagesize()的用法。
9 为上传图片添加水印效果。
10 生成已有图片的缩略图。
11 使用函数imagecopyresampled()。
12 生成带有底纹的数字验证码图片的php程序。

*/

//1 生成一个简单图像。

 代码如下 复制代码

$width = 200;
$height =200;

$img =  imagecreatetruecolor($width,$height) or die("不支持gd图像处理");
imagepng($img);
imagedestroy($img);

//2 设定图像的颜色。

 代码如下 复制代码

$width = 200;
$height =200;

$img =  imagecreatetruecolor($width,$height) or die("不支持gd图像处理");

$bg_color = imagecolorallocate($img, 255, 0, 0);
imagefill($img, 0, 0, $bg_color);

imagepng($img);
imagedestroy($img);

//3 在图像上绘制直线。

 代码如下 复制代码

$width = 200;
$height =300;

$img =  imagecreatetruecolor($width,$height) or die("不支持gd图像处理");

$line_color = imagecolorallocate($img, 255, 255, 255);
imageline($img,0,40,200,40,$line_color);
imageline($img,0,260,200,260,$line_color);

imagepng($img);
imagedestroy($img);

//4 在图像上显示文字。

 代码如下 复制代码

$width = 200;
$height =300;

$img =  imagecreatetruecolor($width,$height) or die("不支持gd图像处理");
$line_color = imagecolorallocate($img, 255, 255, 255);

imageline($img, 0, 40, 200, 40, $line_color);
imageline($img, 0, 260, 200, 260, $line_color);
imagestring($img, 5, 0, 60, "it's time to learn php!", $line_color);

imagepng($img);
imagedestroy($img);

//5 在图像中显示中文字符。

 代码如下 复制代码

$width = 200;
$height =300;

$img =  imagecreatetruecolor($width,$height) or die("不支持gd图像处理");
$line_color = imagecolorallocate($img, 255, 255, 255);
$font_type ="c://windows//fonts//simli.ttf";    //获取truetype字体,采用隶书字体

//“西游记”3个字16进制字符
$cn_char1 = chr(0xe8).chr(0xa5).chr(0xbf);
$cn_char2 = chr(0xe6).chr(0xb8).chr(0xb8);
$cn_char3 = chr(0xe8).chr(0xae).chr(0xb0);

//“吴承恩著”4个字16进制字符
$cn_str = chr(0xe5).chr(0x90).chr(0xb4).chr(0xe6).chr(0x89).chr(0xbf).chr(0xe6).chr(0x81).chr(0xa9);
$cn_str .= " ".chr(0xe8).chr(0x91).chr(0x97);

imageline($img, 0, 40, 200, 40, $line_color);
imageline($img, 0, 260, 200, 260, $line_color);

//竖排显示“西游记”3字
imagettftext($img, 30, 0, 10, 80, $line_color, $font_type,$cn_char1);
imagettftext($img, 30, 0, 10, 120, $line_color, $font_type,$cn_char2);
imagettftext($img, 30, 0, 10, 160, $line_color, $font_type,$cn_char3);

//横排显示“吴承恩著”4字
imagettftext($img, 15, 0, 90, 254, $line_color, $font_type,$cn_str);

imagepng($img);
imagedestroy($img);

//6 打开已存在的图片。
$img=imagecreatefromjpeg("tower.jpg");

imagejpeg($img);
imagedestroy($img);

//7 获取图片的相关属性。
$img=imagecreatefromjpeg("tower.jpg");

$x = imagesx($img);
$y = imagesy($img);
echo "图片tower.jpg的宽为:<b>$x</b> pixels";
echo "<br/>";
echo "<br/>";
echo "图片tower.jpg的高为:<b>$y</b> pixels";

//8 函数getimagesize()的用法。
$img_info=getimagesize("tower.jpg");

for($i=0; $i<4; ++$i)
{
    echo $img_info[$i];
    echo "<br/>";
}

?>

[!--infotagslink--]

相关文章

  • PS怎么排除重叠图形

    PS排除重叠形状是什么意思?很多朋友都不是很清楚,其实方法很简单的,下面小编就为大家介绍介绍一下,不会的朋友可以参考本文,来看看吧。 步骤:1、在PS中,选择“矩形工具...2016-12-31
  • php二维码生成

    本文介绍两种使用 php 生成二维码的方法。 (1)利用google生成二维码的开放接口,代码如下: /** * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param strin...2015-10-21
  • Java生成随机姓名、性别和年龄的实现示例

    这篇文章主要介绍了Java生成随机姓名、性别和年龄的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-01
  • C#生成随机数功能示例

    这篇文章主要介绍了C#生成随机数功能,涉及C#数学运算与字符串操作相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • jQuery为动态生成的select元素添加事件的方法

    下面小编就为大家带来一篇jQuery为动态生成的select元素添加事件的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-09-01
  • php生成唯一数字id的方法汇总

    关于生成唯一数字ID的问题,是不是需要使用rand生成一个随机数,然后去数据库查询是否有这个数呢?感觉这样的话有点费时间,有没有其他方法呢?当然不是,其实有两种方法可以解决。 1. 如果你只用php而不用数据库的话,那时间戳+随...2015-11-24
  • PHP自动生成后台导航网址的最佳方法

    经常制作开发不同的网站的后台,写过很多种不同的后台导航写法。 最终积累了这种最写法,算是最好的吧...2013-09-29
  • C#统计字符串中数字个数的方法

    这篇文章主要介绍了C#统计字符串中数字个数的方法,涉及C#遍历字符串并判断数字的技巧,需要的朋友可以参考下...2020-06-25
  • js生成随机数的方法实例

    js生成随机数主要用到了内置的Math对象的random()方法。用法如:Math.random()。它返回的是一个 0 ~ 1 之间的随机数。有了这么一个方法,那生成任意随机数就好理解了。比如实际中我们可能会有如下的需要: (1)生成一个 0 - 1...2015-10-21
  • PHP验证码生成与验证例子

    验证码是一个现在WEB2.0中常见的一个功能了,像注册、登录又或者是留言页面,都需要注册码来验证当前操作者的合法性,我们会看到有些网站没有验证码,但那是更高级的验证了,...2016-11-25
  • PHP生成不同颜色、不同大小的tag标签函数

    复制代码 代码如下:function getTagStyle(){ $minFontSize=8; //最小字体大小,可根据需要自行更改 $maxFontSize=18; //最大字体大小,可根据需要自行更改 return 'font-size:'.($minFontSize+lcg_value()*(abs($maxFo...2013-10-04
  • php中利用str_pad函数生成数字递增形式的产品编号

    解决办法:$str=”QB”.str_pad(($maxid[0]["max(id)"]+1),5,”0″,STR_PAD_LEFT ); 其中$maxid[0]["max(id)"]+1) 是利用max函数从数据库中找也ID最大的一个值, ID为主键,不会重复。 str_pad() 函数把字符串填充为指...2013-10-04
  • JS生成某个范围的随机数【四种情况详解】

    下面小编就为大家带来一篇JS生成某个范围的随机数【四种情况详解】。小编觉得挺不错的,现在分享给大家,也给大家做个参考,一起跟随小编过来看看吧...2016-04-22
  • C#生成Word文档代码示例

    这篇文章主要介绍了C#生成Word文档代码示例,本文直接给出代码实例,需要的朋友可以参考下...2020-06-25
  • R语言学习ggplot2绘制统计图形包全面详解

    这篇文章主要为大家详细介绍了R语言学习ggplot2绘制统计图形包的全面知识讲解,有需要的朋友可以借鉴参考下,希望能够有所帮助...2021-11-06
  • vivo x9怎么设置图形解锁?vivo x9设置图形解锁教程

    本篇文章介绍了vivo x9如何设置图形解锁的教程,手机小白们快来看一看吧。 问:vivo x9怎么设置图形解锁? 答:图形解锁在某种程度上会保护我们的隐私,那么怎么设置图形...2017-01-22
  • JS+JSP通过img标签调用实现静态页面访问次数统计的方法

    这篇文章主要介绍了JS+JSP通过img标签调用实现静态页面访问次数统计的方法,基于JavaScript动态调用jsp页面通过对TXT文本文件的读写实现统计访问次数的功能,需要的朋友可以参考下...2015-12-16
  • Linux下统计当前文件夹下的文件个数、目录个数

    这篇文章主要介绍了Linux下统计当前文件夹下的文件个数、目录个数,本文使用ls命令配合管理、grep命令实现统计需求,需要的朋友可以参考下...2020-07-11
  • Vue组件文档生成工具库的方法

    本文主要介绍了Vue组件文档生成工具库的方法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-08-11
  • PHP简单实现生成txt文件到指定目录的方法

    这篇文章主要介绍了PHP简单实现生成txt文件到指定目录的方法,简单对比分析了PHP中fwrite及file_put_contents等函数的使用方法,需要的朋友可以参考下...2016-04-28