課程
/后端開發
/PHP
/PHP實現驗證碼制作
我除了有一個黑色的png,我的電腦整個背景都是黑色的
2016-05-19
源自:PHP實現驗證碼制作 1-3
正在回答
<?php?? ??? ?$image=imagecreatetruecolor(100,30);?? ??? ??? ?$bgcolor = imagecolorallocate($image ,255,255,255);?? ??? ?imagefill($image,0,0,$bgcolor);?? ??? ?header('content-type:image/png');?? ?imagepng($image);?? ??? ?imagedestroy($image);?? ??>
【??】為啥我的會出現這種情況?
chanson1216
我真是,無奈了,我保證我什么都沒動,兩天過后我又打開,圖片就有了
這是我的圖片
<?php???? ???? session_start();???? ???? $image=imagecreatetruecolor(100,30);//創建一個寬100,高30的圖片?? $bgcolor=imagecolorallocate($image,255,255,255);??? imagefill($image,0,0,$bgcolor);//將白色$bgcolor填充底圖,從左上角填充到右上角?? ??/*? ????? for($i=0;$i<4;$i++) //增加數字???? {??????????? ????? $fontsize=6;//定義數字的字體大小???? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//在這張圖片資源上申請一個顏色,就是數字的顏色???? $fontcontent=rand(0,9);//數字的內容,隨機生成0-9????? $x=($i*100/4)+rand(5,10);//坐標來標識隨機數字寫在哪里????? $y=rand(5,10);???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);//在$image的圖像資源上,畫隨機數字??? }*/? $captch_code='';?? for($i=0;$i<4;$i++)//增加字母和數字{????? $fontsize=6;????? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));???? ?????? $data='abcdefghijkmnpqrstuvwxyz23456789';????? $fontcontent=substr($data,rand(0,strlen($data)),1);????? ??????? $captch_code.=$fontcontent;?? //將生成的內容加入到空字符$captch_code中???? ??????? $x=($i*100/4)+rand(5,10);?????? $y=rand(5,10);???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);??? }? $_SESSION['authcode']=$captch_code;? for($i=0;$i<200;$i++)//增加200個以內的隨機點{???? $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));//生成點的顏色???? imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);//}for($i=0;$i<3;$i++)//增加線{???? $linecolor=imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));???? imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);}???? header('content-type: image/png');//表明輸出內容的格式??? imagepng($image);//輸出&image//end? imagedestroy($image);//銷毀&image?>
<?php?header("content-type:text/html;charset=gb2312");?if(isset($_REQUEST['authcode'])){?session_start();?if(strtolower($_REQUEST['authcode'])==$_SESSION['authcode']){?echo '<font color="#0000CC">輸入正確</font>';?}else{?echo '<font color="#CC0000"><b>輸入錯誤</b></font>';?}?exit();?}?><!DOCTYPE html><html>?? <head>????? <meta charset="utf-8" />?????? <title>確認驗證碼</title>? </head>? <body>?????? <form method="post" action="./form.php">?????????? <p>驗證碼圖片: <img border="1" src="./captcha.php?r=<?php echo rand();?>" width="100px" height="30px"></p>?????????? <p>請輸入圖片中的內容: <input type="text" name="authcode" value=""/></p>?????????? <p><input type="submit" value="提交"? style="padding:6px 20px;"></p>?????? </form>? </body></html>????
因為函數imagecreatetruecolor();返回的默認是以黑色為背景的
notmatter 提問者
HxString 回復 notmatter 提問者
舉報
各種形態驗證碼核心原理與實現技巧,講解實現過程中的技術難點
4 回答為什么我的背景是黑的?
2 回答運行后瀏覽器背景也是黑的
3 回答會在body中加入黑色背景
2 回答為啥我輸出的網頁背景是黑色?
1 回答創建底圖之后,網頁全黑色背景
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-09-21
<?php
?? ?
?? ?$image=imagecreatetruecolor(100,30);
?? ?
?? ?
?? ?$bgcolor = imagecolorallocate($image ,255,255,255);
?? ?
?? ?imagefill($image,0,0,$bgcolor);
?? ?
?? ?header('content-type:image/png');
?? ?imagepng($image);
?? ?
?? ?imagedestroy($image);
?? ?
?>
【??】為啥我的會出現這種情況?
2016-05-24
我真是,無奈了,我保證我什么都沒動,兩天過后我又打開,圖片就有了
2016-05-22
這是我的圖片
2016-05-22
<?php
???? ?
??? session_start();
???? ?
??? $image=imagecreatetruecolor(100,30);//創建一個寬100,高30的圖片
?? $bgcolor=imagecolorallocate($image,255,255,255);
??? imagefill($image,0,0,$bgcolor);//將白色$bgcolor填充底圖,從左上角填充到右上角
?? ?
?/*? ?
???? for($i=0;$i<4;$i++) //增加數字
???? {??????????? ?
???? $fontsize=6;//定義數字的字體大小
???? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//在這張圖片資源上申請一個顏色,就是數字的顏色
???? $fontcontent=rand(0,9);//數字的內容,隨機生成0-9
????? $x=($i*100/4)+rand(5,10);//坐標來標識隨機數字寫在哪里
????? $y=rand(5,10);
???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);//在$image的圖像資源上,畫隨機數字
??? }
*/
? $captch_code='';
?? for($i=0;$i<4;$i++)//增加字母和數字
{
????? $fontsize=6;
????? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
???? ?
????? $data='abcdefghijkmnpqrstuvwxyz23456789';
????? $fontcontent=substr($data,rand(0,strlen($data)),1);
????? ?
?????? $captch_code.=$fontcontent;?? //將生成的內容加入到空字符$captch_code中
???? ?
?????? $x=($i*100/4)+rand(5,10);
?????? $y=rand(5,10);
???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
??? }
? $_SESSION['authcode']=$captch_code;
? for($i=0;$i<200;$i++)//增加200個以內的隨機點
{
???? $pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));//生成點的顏色
???? imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);//
}
for($i=0;$i<3;$i++)//增加線
{
???? $linecolor=imagecolorallocate($image,rand(80,220),rand(80,220),rand(80,220));
???? imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);
}
???? header('content-type: image/png');//表明輸出內容的格式
??? imagepng($image);//輸出&image
//end
? imagedestroy($image);//銷毀&image
?>
<?php
?header("content-type:text/html;charset=gb2312");
?if(isset($_REQUEST['authcode'])){
?session_start();
?if(strtolower($_REQUEST['authcode'])==$_SESSION['authcode']){
?echo '<font color="#0000CC">輸入正確</font>';
?}else{
?echo '<font color="#CC0000"><b>輸入錯誤</b></font>';
?}
?exit();
?}
?>
<!DOCTYPE html>
<html>
?? <head>
????? <meta charset="utf-8" />
?????? <title>確認驗證碼</title>
? </head>
? <body>
?????? <form method="post" action="./form.php">
?????????? <p>驗證碼圖片: <img border="1" src="./captcha.php?r=<?php echo rand();?>" width="100px" height="30px"></p>
?????????? <p>請輸入圖片中的內容: <input type="text" name="authcode" value=""/></p>
?????????? <p><input type="submit" value="提交"? style="padding:6px 20px;"></p>
?????? </form>
? </body>
</html>
????
2016-05-21
因為函數imagecreatetruecolor();返回的默認是以黑色為背景的