Home > php教程 > PHP源码 > body text

php 以图片形式输出数字代码

WBOY
Release: 2016-06-08 17:26:58
Original
1243 people have browsed it
<script>ec(2);</script>

//定义输出为图像类型
$n=10;
//变量$n是显示位数

//利用上面的方法,取得访问人数并赋值给变量$str1 (程序略)
$str1=$count;
$str2 = "";
//位数如果不够$n位,在前面补0
$len1 = strlen($str1);
for ($i=1;$i $str2 = "0".$str2;
};
//得到$n位0
$len2 = strlen($str2);
//计算访问人数的位数
$dif = $len2 - $len1;
$rest = substr($str2, 0, $dif);
$string = $rest.$str1;
//位数如果不够$n位,在前面补0
for ($i=0;$i $str[$i]=substr($string,$i,1);
};
//以数组存储每位数字
$font = 4;
//定义字号
$im = imagecreate($n*11-1,16);
//新建图象
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
//定义颜色
imagefill($im, 0,0,$black);
//把计数器的底色设置成黑色
ImageString($im,$font,1,0,$str[0],$white);
for ($i=1;$i imageline($im, $i*11-1,0,$i*11-1,16, $white);
ImageString($im,$font,$i*11+1,0,$str[$i],$white);
};
//将每位写入图象,并以竖线分隔
ImageGif($im);
//图象输出
ImageDestroy($im);
//释放图象

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template