1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php 验证码字体居中 自定义验证码图片的宽高后文本垂直水平居中[帝国cms ShowKey.p

php 验证码字体居中 自定义验证码图片的宽高后文本垂直水平居中[帝国cms ShowKey.p

时间:2022-12-18 17:34:34

相关推荐

php 验证码字体居中 自定义验证码图片的宽高后文本垂直水平居中[帝国cms ShowKey.p

define('EmpireCMSAdmin','1');

define('EmpireCMSAPage','login');

define('EmpireCMSNFPage','1');

require('../class/connect.php');

//绘制居中文本, 对于GD的内置字体

function pc_ImageStringCenter($image,$text,$font){

//字体大小

$width = array(1=>5,6,7,8,9);

$height = array(1=>6,8,13,15,15);

//计算图像大小

$xi = imagesx($image);

$yi = imagesy($image);

//计算文本大小

$xr = $width[$font] * strlen($text);

$yr = $height[$font];

//计算中心点的位置

$x=intval(($xi-$xr)/2);

$y=intval(($yi-$yr)/2);

return array($x,$y);

}

//取得随机数

function domake_password($pw_length){

global $public_r;

//验证码字符组成,0数字,1字母,2数字+字母

if($public_r["keytog"]==1)

{

$low_ascii_bound=65;

$upper_ascii_bound=90;

$notuse=array(73,79);

}

elseif($public_r["keytog"]==2)

{

$low_ascii_bound=50;

$upper_ascii_bound=90;

//过滤一些特殊符号和容易看错的字母

//58(:) 59(;) 60() 63(?) 64(@) 73(I) 76(L) 79(O)

$notuse=array(58,59,60,61,62,63,64,73,76,79);

}

else

{

$low_ascii_bound=48;

$upper_ascii_bound=57;

$notuse=array(48,49);

}

while($i

if(PHP_VERSION

{

mt_srand((double)microtime()*1000000);

}

$randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);

if(!in_array($randnum,$notuse))

{

$password1=$password1.chr($randnum);

$i++;

}

}

return $password1;

}

//返回颜色

function ReturnShowKeyColor($img){

global $public_r;

//背景色

if($public_r["keybgcolor"])

{

$bgcr=ToReturnRGB($public_r["keybgcolor"]);

$r["bgcolor"]=imagecolorallocate($img,$bgcr[0],$bgcr[1],$bgcr[2]);

}

else

{

$r["bgcolor"]=imagecolorallocate($img,7,27,63);

}

//文字色

if($public_r["keyfontcolor"])

{

$fcr=ToReturnRGB($public_r["keyfontcolor"]);

$r["fontcolor"]=ImageColorAllocate($img,$fcr[0],$fcr[1],$fcr[2]);

}

else

{

$r["fontcolor"]=ImageColorAllocate($img,255,255,255);

}

//干扰色

if($public_r["keydistcolor"])

{

$dcr=ToReturnRGB($public_r["keydistcolor"]);

$r["distcolor"]=ImageColorAllocate($img,$dcr[0],$dcr[1],$dcr[2]);

}

else

{

$r["distcolor"]=ImageColorAllocate($img,255,255,255);

}

return $r;

}

//显示验证码

function ShowKey($v){

$vname=ecmsReturnKeyVarname($v);

//取得四位随机验证码

$key=strtolower(domake_password(4));

//设置验证码

ecmsSetShowKey($vname,$key,0);

//是否支持gd库

if(function_exists("imagegif"))

{

header("Content-type:image/gif");

$img=imagecreate(60,32);

$colorr=ReturnShowKeyColor($img);

$bgcolor=$colorr["bgcolor"];

$fontcolor=$colorr["fontcolor"];

$distcolor=$colorr["distcolor"];

imagefill($img,0,0,$bgcolor);

list($x,$y)=pc_ImageStringCenter($img,$key,5);

imagestring($img,5,$x,$y,$key,$fontcolor);

//for($i=0;$i<90;$i++)

//{

//imagesetpixel($img,rand()%70,rand()%30,$distcolor);

//}

imagegif($img);

imagedestroy($img);

}

elseif(function_exists("imagepng"))

{

header("Content-type:image/png");

$img=imagecreate(50,26);

$colorr=ReturnShowKeyColor($img);

$bgcolor=$colorr["bgcolor"];

$fontcolor=$colorr["fontcolor"];

$distcolor=$colorr["distcolor"];

imagefill($img,0,0,$bgcolor);

imagestring($img,5,6,3,$key,$fontcolor);

for($i=0;$i<90;$i++)

{

imagesetpixel($img,rand()%70,rand()%30,$distcolor);

}

imagepng($img);

imagedestroy($img);

}

elseif(function_exists("imagejpeg"))

{

header("Content-type:image/jpeg");

$img=imagecreate(50,26);

$colorr=ReturnShowKeyColor($img);

$bgcolor=$colorr["bgcolor"];

$fontcolor=$colorr["fontcolor"];

$distcolor=$colorr["distcolor"];

imagefill($img,0,0,$bgcolor);

imagestring($img,5,6,3,$key,$fontcolor);

for($i=0;$i<90;$i++)

{

imagesetpixel($img,rand()%70,rand()%30,$distcolor);

}

imagejpeg($img);

imagedestroy($img);

}

elseif(function_exists("imagewbmp"))

{

header("Content-type:image/vnd.wap.wbmp");

$img=imagecreate(50,26);

$colorr=ReturnShowKeyColor($img);

$bgcolor=$colorr["bgcolor"];

$fontcolor=$colorr["fontcolor"];

$distcolor=$colorr["distcolor"];

imagefill($img,0,0,$bgcolor);

imagestring($img,5,6,3,$key,$fontcolor);

for($i=0;$i<90;$i++)

{

imagesetpixel($img,rand()%70,rand()%30,$distcolor);

}

imagewbmp($img);

imagedestroy($img);

}

else

{

ecmsSetShowKey($vname,"ecms",0);

echo ReadFiletext("../data/images/ecms.jpg");

}

}

//返回变量名

function ecmsReturnKeyVarname($v){

$name="checkkey";

return $name;

}

$v=$_GET["v"];

ShowKey($v);

?>

php 验证码字体居中 自定义验证码图片的宽高后文本垂直水平居中[帝国cms ShowKey.php]-网站程序网...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。