亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP ??? ?? ? ??? ???? ?? ???? ??

???? ??

??? ? ?? ???? ????? ???? ?? ?? ??? ?? ???, ?? ?? ?? ???? ?? ??? ??? ????? ?? ???? ???????. ?? ????? ???? ????? ???? ???? ?????. ? ????? ?? ??? ?? ????? ?????. ? ??? ???? ???? ??? ??? ??? ? ????. ?? ?? ??? ?? ??? ???



???? ??? ?? ???? ?????

生成驗(yàn)證碼的流程圖.png

?? ?? ?? ??? ??


1. php? GD ??? ??????
php.ini ??? ?? ???=php_gd2.dll? ??? ???? ??????. ?? ????? ??? ??? ??? ????.

???? 60X15 ?? ?? ???

2. ??? ???? ??? ???

p1.png

? ????. ??? ? ?? ??? ??????.

? ??? ???(New)

ImageCreate(??, ??), ??? ?? ???? ????.
  • imageCreateTrueColor(width, height); ?? ?? ???? ????.

  • ???? ???? ??? ???(??)

imageCreateFromJPEG(??? ??);
  • imageCreateFromPNG(??? ??);

    imageCreateFromGIF(??? ??);

    ?? ?? ???? ????.

$width=60;

$height=15;

//??? ???

$img=imageCreateTrueColor($width,$height);

$img? ??? var_dump()? ??? ???. ?? ??? ??? ?????? 3. ??? ??


?? ??
: ???? ?? ??? ???? ?? ?? ?? ???? ??? ???? ???.

?? ??:

Color ID = imageColorAllocate(canvas, R, G, B)

//?? ?? $white = imageColorAllocate($img,0xff,0xff,0xff);

??? ???

: ??? ?, ?? ?? ??? ???? ???(??)

?? ??:

imageFill(???, ??? ?? x, ??? ?? Y, ?? ??)? ???? ??

??? ??? ???? ?????.

??: 0, 0, ??? ?? ??.

????? ??? x?? ????, ??? ??? Y?? ?????.

//???? ?? ???
imageFill($img,0,0,$white);

4. ???? ??

???? ????.

??:

  • ??? ??? ?????.

  • ?? ??.

?? ??:

imagePNG(canvas[, ?? ??])://??? ??? ?? ??

imageJPEG();//? ???? ?? ??, ?? ?? ??? ? ??? ?????

imageGIF();//??? ??

? ?? ????? ??? ?? ??? ?????.

????? ?? ????? ?? ??? ??? PNG ?? ????? ?? ????? ??? ???.

Content-type

//?? ??

header('Content -Type:image /jpeg;');

imageJPEG($img);

??: ???? ??? ???? ?? ? ??? ? ????!

5. ??? ??? ??

?? ??: imageDestroy();

imageDestroy($img);



?? ?? ? ??

1. ?? ??? ?? ??? ???? ?? ??? ? ??? ????? ?? ??? ??? ??? ???. ??? ??? ????.

//?? ?? ?? ?????.

$chars = '1234567890' ;//??? ? ?? ??

$chars_len=strlen($chars);

$code_len=4;//???? ??$code='';//??? ?? ?? ???



2 4?, ?? ??? ?? ???? ??? ???? ????? ? ??? ???? ?? ?? ?? ?????

for($i= 1;$i<=$code_len ;++$i){ $rand=mt_rand(0,$chars_len-1);//0~9 ??? ???? ?? ??

$code.=$rand;//?? ??? ??? ???

}


3. ??? ?? ???? ?? ??? ???? ??

//??? ?? ??? ??------ -- ---------------session_start();

$_SESSION[' ver_code']=$code;



???? ??? ???? ?? ????? image

1. ???? ?? ??? ??? ?????

//??? ??? ??? ?????$str_color=imageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand (0,255)) ;


2. ???? ?? ??? ?? ?? ???? ?????

//???? ?? ??
//??? ??
$font=5;
//??? ??
$img_w=imageSX($img);
$img_h=imageSY($img);
//Font
$font_w=imagefontwidth($font);
$font_h=imagefontheight($font);
//???? ??
$code_w=$font_w*$code_len;
$code_h=$font_h;
$x = ($img_w-$code_w)/2;
$y=($img_h-$code_h)/2;
//???? ???? ??--------------- - ------------
imageString($img,$font,$x,$y,$code,$str_color);

3. ???? ??

/ /?? ??
imageJPEG($img);
imageDestroy($img);


?? ??? ??? ????

<?php
//生成驗(yàn)證碼背景圖---------------------------------
header('Content-Type:image/jpeg;');
//背景圖尺寸
$width=60;
$height=15;
//創(chuàng)建畫布
$img=imageCreateTrueColor($width,$height);
//分配顏色
$white = imageColorAllocate($img,0xff,0xff,0xff);
//填充顏色到畫布
imageFill($img,0,0,$white);
//生成驗(yàn)證碼的值----------------------------------
$chars = '1234567890';//所以可能出現(xiàn)的字符
$chars_len=strlen($chars);
$code_len=4;//驗(yàn)證碼的長度
$code='';//初始化驗(yàn)證碼字符串
for($i=1;$i<=$code_len;++$i){
    $rand=mt_rand(0,$chars_len-1);//隨機(jī)取0-9中的任意一個(gè)數(shù)字
    $code.=$rand;//將取出來的數(shù)字連接在一起
}
//存入session中,用于驗(yàn)證-------------------------
session_start();
$_SESSION['ver_code']=$code;
//隨機(jī)分配字符串顏色------------------------------
$str_color=imageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
//計(jì)算字符串的居中
//字符串大小
$font=5;
//畫布尺寸
$img_w=imageSX($img);
$img_h=imageSY($img);
//字體的尺寸
$font_w=imagefontwidth($font);
$font_h=imagefontheight($font);
//字符串的尺寸
$code_w=$font_w*$code_len;
$code_h=$font_h;
$x=($img_w-$code_w)/2;
$y=($img_h-$code_h)/2;
//把驗(yàn)證碼輸出到畫布上----------------------------
imageString($img,$font,$x,$y,$code,$str_color);
//直接輸出
imageJPEG($img);
imageDestroy($img);
?>


???? ??
||
<?php //生成驗(yàn)證碼背景圖--------------------------------- header('Content-Type:image/jpeg;'); //背景圖尺寸 $width=60; $height=15; //創(chuàng)建畫布 $img=imageCreateTrueColor($width,$height); //分配顏色 $white = imageColorAllocate($img,0xff,0xff,0xff); //填充顏色到畫布 imageFill($img,0,0,$white); //生成驗(yàn)證碼的值---------------------------------- $chars = '1234567890';//所以可能出現(xiàn)的字符 $chars_len=strlen($chars); $code_len=4;//驗(yàn)證碼的長度 $code='';//初始化驗(yàn)證碼字符串 for($i=1;$i<=$code_len;++$i){ $rand=mt_rand(0,$chars_len-1);//隨機(jī)取0-9中的任意一個(gè)數(shù)字 $code.=$rand;//將取出來的數(shù)字連接在一起 } //存入session中,用于驗(yàn)證------------------------- session_start(); $_SESSION['ver_code']=$code; //隨機(jī)分配字符串顏色------------------------------ $str_color=imageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); //計(jì)算字符串的居中 //字符串大小 $font=5; //畫布尺寸 $img_w=imageSX($img); $img_h=imageSY($img); //字體的尺寸 $font_w=imagefontwidth($font); $font_h=imagefontheight($font); //字符串的尺寸 $code_w=$font_w*$code_len; $code_h=$font_h; $x=($img_w-$code_w)/2; $y=($img_h-$code_h)/2; //把驗(yàn)證碼輸出到畫布上---------------------------- imageString($img,$font,$x,$y,$code,$str_color); //直接輸出 imageJPEG($img); imageDestroy($img); ?>