用的老师的源码 图片是裂的
<?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ҩjua8b<59|D;
下面那段代码在本地是裂的
php扩展是这样的