|
<?php
function yzm($name,$width,$height){
Header("Content-type: image/PNG");
srand((double)microtime()*1000000);//播下一個(gè)生成隨機(jī)數(shù)字的種子,以方便下面隨機(jī)數(shù)生成的使用
session_start();//將隨機(jī)數(shù)存入session中
$_SESSION[$name]="";
$im = imagecreate($width,$height); //制定圖片背景大小
$black = ImageColorAllocate($im, 0,0,0); //設(shè)定三種顏色
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray); //采用區(qū)域填充法,設(shè)定(0,0)
while(($authnum=rand()%100000)<10000);
$_SESSION[$name]=$authnum;
imagestring($im, 5, 10, 3, $authnum, $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);
}?>
使用方法,將其建立一個(gè)php文件入yzm.php,調(diào)用<img src="aaa.php?w=100&h=20&name=aaa">
將參數(shù)調(diào)用到本函數(shù)中即可。
php技術(shù):簡(jiǎn)單的php 驗(yàn)證圖片生成函數(shù),轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。