用的老師的源碼 圖片是裂的
<?php require?'string.func.php'; /* //通過GD庫做驗證碼 //創建畫布 $width=200; $height=40; $image=imagecreatetruecolor($width,$height); $white=imagecolorallocate($image,?255,?255,?28); //畫布顏色 $black=imagecolorallocate($image,?0,?0,?0); //畫筆顏色 imagefill($image,0,0,$white); //用填充矩形填充畫布 //imagefilledrectangle($image,?1,?1,$width?-?1,?$heigth?-?1,?$white); $type=1; $length=4; $chars=buildRandomString($type,$length); //echo?$chars; imagestring($image,?5,?10,?10,?$chars,?$black); for($i=0;$i<50;$i++)?{ ??imagesetpixel($image,?rand(0,?200)?,?rand(0,?40)?,?$black);? } header("content-type:?image/gif"); imagepng($image); imagedestroy($image); /* $sess_name="verify"; $_SESSION[$sess_name]=$chars; $fontfiles=array("msyh.ttc","msyhbd.ttc","msyhl.ttc","simfang.ttf","simhei.ttf","simkai.ttf","simsun.ttc"); for?($i=9;$i<$length;$i++){ ????$size=mt_rand(14,18); ????$angle=mt_rand(-15,15); ????$x=5+$i*$size; ????$y=mt_rand(20,26); ????$fontfile="../fonts/".$fontfiles[mt_rand(0,count($fontfiles)-1)]; ????$color=imagecolorallocate($image,?mt_rand(50,90),?mt_rand(80,200),?mt_rand(90,180)); ????$text=substr($chars,$i,1); ????imagettftext($image,?$size,?$angle,?$x,?$y,?$color,?$fontfile,?$text); } header("content-type:image/gif"); imagegif($image); imagedestroy($image); */ $width?=?80; $height?=?28; $image?=?imagecreatetruecolor?(?$width,?$height?); $white?=?imagecolorallocate?(?$image,?255,?255,?255?); $black?=?imagecolorallocate?(?$image,?0,?0,?0?); //用填充矩形填充畫布 imagefilledrectangle?(?$image,?1,?1,?$width?-?2,?$height?-?2,?$white?); $chars?=?buildRandomString?(?$type,?$length?); $_SESSION[$sess_name]?=?$chars; //$fontfiles?=?array?("MSYH.TTF",?"MSYHBD.TTF",?"SIMLI.TTF",?"SIMSUN.TTC",?"SIMYOU.TTF",?"STZHONGS.TTF"?); $fontfiles?=?array?("msyh.ttc"?); //由于字體文件比較大就只保留一個字體如果有需要的同學可以自己添加字體字體在你的電腦中的fonts文件夾里有直接運行輸入fonts就能看到相應字體 for($i?=?0;?$i?<?$length;?$i?++)?{ $size?=?mt_rand?(?14,?18?); $angle?=?mt_rand?(?-?15,?15?); $x?=?5?+?$i?*?$size; $y?=?mt_rand?(?20,?26?); $fontfile?=?"../fonts/"?.?$fontfiles?[mt_rand?(?0,?count?(?$fontfiles?)?-?1?)]; $color?=?imagecolorallocate?(?$image,?mt_rand?(?50,?90?),?mt_rand?(?80,?200?),?mt_rand?(?90,?180?)?); //$text?=?substr?(?$chars,?$i,?1?); imagettftext?(?$image,?$size,?$angle,?$x,?$y,?$color,?$fontfile,?$chars?); } if?($pixel)?{ for($i?=?0;?$i?<?50;?$i?++)?{ imagesetpixel?(?$image,?mt_rand?(?0,?$width?-?1?),?mt_rand?(?0,?$height?-?1?),?$text?); } } if?($line)?{ for($i?=?1;?$i?<?$line;?$i?++)?{ $color?=?imagecolorallocate?(?$image,?mt_rand?(?50,?90?),?mt_rand?(?80,?200?),?mt_rand?(?90,?180?)?); imageline?(?$image,?mt_rand?(?0,?$width?-?1?),?mt_rand?(?0,?$height?-?1?),?mt_rand?(?0,?$width?-?1?),?mt_rand?(?0,?$height?-?1?),?$color?); } } header("content-type:image/gif"); imagegif($image); imagedestroy($image);
這是老師的源碼 圖片是裂的?
把編碼從utf-8 改成無bom的之后在vps是
這樣的 本地是
( ! )?Notice: Undefined variable: type in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?64
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Notice: Undefined variable: length in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?64
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Notice: Undefined variable: sess_name in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?65
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Notice: Undefined variable: length in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?69
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Notice: Undefined variable: pixel in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?79
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Notice: Undefined variable: line in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?84
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
( ! )?Warning: Cannot modify header information - headers already sent by (output started at E:\imooc\xuexi01\shopimooc\lib\image.func.php:79) in E:\imooc\xuexi01\shopimooc\lib\image.func.php on line?92
Call Stack
#
Time
Memory
Function
Location
1 ? ?0.0019 ? ?255480 ? ?{main}( ) ? ?..\image.func.php:0 ? ?
2 ? ?0.1372 ? ?286960 ? ?header?( ) ? ?..\image.func.php:92 ? ?
GIF87aP,P_O??}???Z> /1P< J{Bm?jua8?b<59|D;
2017-03-21
翻了好幾頁的問題,終于遇見個一樣的了
用老師源代碼出不來效果,用基礎課的代碼能出來……
不明白為什么……
2016-03-24
$fontfiles?=?array?("msyh.ttc"?); ? //字體文件要大寫!
2015-12-29
2015-12-29