圖片出不來
就是圖片出不來,求大神指點,急求
這是我的代碼
<?php
???? ?
??? session_start();
???? ?
??? $image=imagecreatetruecolor(100,30);//創(chuàng)建一個寬100,高30的圖片
?? $bgcolor=imagecolorallocate($image,255,255,255);
??? imagefill($image,0,0,$bgcolor);//將白色$bgcolor填充底圖,從左上角填充到右上角
?? ?
?/*? ?
???? for($i=0;$i<4;$i++) //增加數(shù)字
???? {??????????? ?
???? $fontsize=6;//定義數(shù)字的字體大小
???? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//在這張圖片資源上申請一個顏色,就是數(shù)字的顏色
???? $fontcontent=rand(0,9);//數(shù)字的內容,隨機生成0-9
????? $x=($i*100/4)+rand(5,10);//坐標來標識隨機數(shù)字寫在哪里
????? $y=rand(5,10);
???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);//在$image的圖像資源上,畫隨機數(shù)字
??? }
*/
? $captch_code='';
?? for($i=0;$i<4;$i++)//增加字母和數(shù)字
{
????? $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-06-02
我,加了? 換一個? 以后又出不來了
應該只是form改了一點吧,我看不出,你再幫我看看白,兩個都貼上好了
<?php
???? ?
??? session_start();
???? ?
??? $image=imagecreatetruecolor(100,30);//創(chuàng)建一個寬100,高30的圖片
?? $bgcolor=imagecolorallocate($image,255,255,255);
??? imagefill($image,0,0,$bgcolor);//將白色$bgcolor填充底圖,從左上角填充到右上角
?? ?
?/*? ?
???? for($i=0;$i<4;$i++) //增加數(shù)字
???? {??????????? ?
???? $fontsize=6;//定義數(shù)字的字體大小
???? $fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//在這張圖片資源上申請一個顏色,就是數(shù)字的顏色
???? $fontcontent=rand(0,9);//數(shù)字的內容,隨機生成0-9
????? $x=($i*100/4)+rand(5,10);//坐標來標識隨機數(shù)字寫在哪里
????? $y=rand(5,10);
???? imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);//在$image的圖像資源上,畫隨機數(shù)字
??? }
*/
? $captch_code='';
?? for($i=0;$i<4;$i++)//增加字母和數(shù)字
{
????? $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 id="captcha_img" border="1" src="./captcha.php?r=<?php echo rand();?>" width="100" height="30"/>
???????????? <a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src='./captcha.php?r='+Math.random()">換一個?</a>
?????????? </p>
?????????? <p>請輸入圖片中的內容: <input type="text" name="authcode" value=""/></p>
?????????? <p><input type="submit" value="提交"? style="padding:6px 20px;"></p>
?????? </form>
? </body>
</html>
????
2016-05-29
ok~~~不用謝
2016-05-24
你好,整篇看下來,說實話沒看出來,
我就未經(jīng)你的允許吧你的代碼完全拷貝到我的文件中去現(xiàn)地做實驗,是可以生成出圖片的
我估計是不是你的文件存儲編碼格式有差別,首先說明,我將你的代碼拷貝后,所有文件的編碼格式都是utf-8的,最終都生成出來了圖片,你自己檢查一下。
同時,我把所有文件都存為utf-8后,我將
<?php
?header("content-type:text/html;charset=gb2312");
?if(isset($_REQUEST['authcode'])){
加粗地方也改成了utf-8,不然我這里顯示亂碼。
ps:
????<p>驗證碼圖片: <img border="1" src="./captcha.php?r=<?php echo rand();?>" width="100px" height="30px"></p>
請問我加粗的地方,你為什么要加這一段代碼?我有點沒看懂,