ubuntu 的PHP服务器,验证码图片不显示字符,怎么回事 ubuntu 的PHP服务器,验证码图片不显示字符,怎么回事?有图片生成,就是没有字符显示.是字符集错误了吗?哪里设置? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?phpfunction getAuthImage($text) { $im_x = 160; $im_y = 40; $im = imagecreatetruecolor($im_x,$im_y); $text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100)); $tmpC0=mt_rand(100,255); $tmpC1=mt_rand(100,255); $tmpC2=mt_rand(100,255); $buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2); imagefill($im, 16, 13, $buttum_c); $font = 't1.ttf'; for ($i=0;$i<strlen($text);$i++) { $tmp =substr($text,$i,1); $array = array(-1,1); $p = array_rand($array); $an = $array[$p]*mt_rand(1,10);//角度 $size = 28; imagettftext($im, $size, $an, 15+$i*$size, 35, $text_c, $font, $tmp); } $distortion_im = imagecreatetruecolor ($im_x, $im_y); imagefill($distortion_im, 16, 13, $buttum_c); for ( $i=0; $i<$im_x; $i++) { for ( $j=0; $j<$im_y; $j++) { $rgb = imagecolorat($im, $i , $j); if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im)&& (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) { imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4) , $j , $rgb); } } } //加入干扰象素; $count = 160;//干扰像素的数量 for($i=0; $i<$count; $i++){ $randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor); } $rand = mt_rand(5,30); $rand1 = mt_rand(15,25); $rand2 = mt_rand(5,10); for ($yy=$rand; $yy<=+$rand+2; $yy++){ for ($px=-80;$px<=80;$px=$px+0.1) { $x=$px/$rand1; if ($x!=0) { $y=sin($x); } $py=$y*$rand2; imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c); } } //设置文件头; Header("Content-type: image/JPEG"); //以PNG格式将图像输出到浏览器或文件; ImagePNG($distortion_im); //销毁一图像,释放与image关联的内存; ImageDestroy($distortion_im); ImageDestroy($im);}function make_rand($length="32"){//验证码文字生成函数 $str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $result=""; for($i=0;$i<$length;$i++){ $num[$i]=rand(0,25); $result.=$str[$num[$i]]; } return $result;}//输出调用$checkcode = make_rand(4);session_start();//将随机数存入session中$_SESSION['helloweba_gg']=strtolower($checkcode);getAuthImage($checkcode);?>windows的服务器可以. 就是ubuntu 不行 windows的服务器可以. 就是ubuntu 不行 <?phpfunction getAuthImage($text) { $im_x = 160; $im_y = 40; $im = imagecreatetruecolor($im_x,$im_y); $text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100)); $tmpC0=mt_rand(100,255); $tmpC1=mt_rand(100,255); $tmpC2=mt_rand(100,255); $buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2); imagefill($im, 16, 13, $buttum_c); $font = 't1.ttf'; for ($i=0;$i<strlen($text);$i++) { $tmp =substr($text,$i,1); $array = array(-1,1); $p = array_rand($array); $an = $array[$p]*mt_rand(1,10);//角度 $size = 28; imagettftext($im, $size, $an, 15+$i*$size, 35, $text_c, $font, $tmp); } $distortion_im = imagecreatetruecolor ($im_x, $im_y); imagefill($distortion_im, 16, 13, $buttum_c); for ( $i=0; $i<$im_x; $i++) { for ( $j=0; $j<$im_y; $j++) { $rgb = imagecolorat($im, $i , $j); if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im)&& (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) { imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4) , $j , $rgb); } } } //加入干扰象素; $count = 160;//干扰像素的数量 for($i=0; $i<$count; $i++){ $randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)); imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor); } $rand = mt_rand(5,30); $rand1 = mt_rand(15,25); $rand2 = mt_rand(5,10); for ($yy=$rand; $yy<=+$rand+2; $yy++){ for ($px=-80;$px<=80;$px=$px+0.1) { $x=$px/$rand1; if ($x!=0) { $y=sin($x); } $py=$y*$rand2; imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c); } } //设置文件头; Header("Content-type: image/JPEG"); //以PNG格式将图像输出到浏览器或文件; ImagePNG($distortion_im); //销毁一图像,释放与image关联的内存; ImageDestroy($distortion_im); ImageDestroy($im);}function make_rand($length="32"){//验证码文字生成函数 $str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $result=""; for($i=0;$i<$length;$i++){ $num[$i]=rand(0,25); $result.=$str[$num[$i]]; } return $result;}//输出调用$checkcode = make_rand(4);session_start();//将随机数存入session中$_SESSION['helloweba_gg']=strtolower($checkcode);getAuthImage($checkcode);?>windows的服务器可以. 就是ubuntu 不行检查你的字体文件路径. 你把 62 行的 Header("Content-type: image/JPEG"); 注释掉就能看到错误信息了ttf 是 windows 的字体文件,你需要安装支持库 本机安装xampp 后的权限设置问题? php如何验证数据库里一个表里面的数据超过5条 自己做的应用怎么在开心网上用PHP应用调用api 通过php程序调用本地播放器 急,100分,跪求大神帮忙,数据采集如何不死机,实时的运行? 新人报告 有没有类似fiddler的工具,可以修改post提交的数据 PHP+MYSQL OA管理系统 求大神门推荐几本php进阶级的书 php商城开发 smarty模板文件.tpl在写标签的样式设置的时候href属性值为什么写“javascript:”就能完成,这样写了怎么实现的,就是样式设置的路径是怎么读取的 急!!!pop服务器怎么分离邮件主体和附件
function getAuthImage($text) {
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x,$im_y);
$text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im, 16, 13, $buttum_c); $font = 't1.ttf'; for ($i=0;$i<strlen($text);$i++)
{
$tmp =substr($text,$i,1);
$array = array(-1,1);
$p = array_rand($array);
$an = $array[$p]*mt_rand(1,10);//角度
$size = 28;
imagettftext($im, $size, $an, 15+$i*$size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor ($im_x, $im_y); imagefill($distortion_im, 16, 13, $buttum_c);
for ( $i=0; $i<$im_x; $i++) {
for ( $j=0; $j<$im_y; $j++) {
$rgb = imagecolorat($im, $i , $j);
if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im)&& (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) {
imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4) , $j , $rgb);
}
}
}
//加入干扰象素;
$count = 160;//干扰像素的数量
for($i=0; $i<$count; $i++){
$randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor);
} $rand = mt_rand(5,30);
$rand1 = mt_rand(15,25);
$rand2 = mt_rand(5,10);
for ($yy=$rand; $yy<=+$rand+2; $yy++){
for ($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if ($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2; imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c);
}
} //设置文件头;
Header("Content-type: image/JPEG"); //以PNG格式将图像输出到浏览器或文件;
ImagePNG($distortion_im); //销毁一图像,释放与image关联的内存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}function make_rand($length="32"){//验证码文字生成函数
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return $result;
}
//输出调用
$checkcode = make_rand(4);
session_start();//将随机数存入session中
$_SESSION['helloweba_gg']=strtolower($checkcode);
getAuthImage($checkcode);
?>windows的服务器可以. 就是ubuntu 不行
function getAuthImage($text) {
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x,$im_y);
$text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im, 16, 13, $buttum_c); $font = 't1.ttf'; for ($i=0;$i<strlen($text);$i++)
{
$tmp =substr($text,$i,1);
$array = array(-1,1);
$p = array_rand($array);
$an = $array[$p]*mt_rand(1,10);//角度
$size = 28;
imagettftext($im, $size, $an, 15+$i*$size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor ($im_x, $im_y); imagefill($distortion_im, 16, 13, $buttum_c);
for ( $i=0; $i<$im_x; $i++) {
for ( $j=0; $j<$im_y; $j++) {
$rgb = imagecolorat($im, $i , $j);
if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im)&& (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) {
imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4) , $j , $rgb);
}
}
}
//加入干扰象素;
$count = 160;//干扰像素的数量
for($i=0; $i<$count; $i++){
$randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor);
} $rand = mt_rand(5,30);
$rand1 = mt_rand(15,25);
$rand2 = mt_rand(5,10);
for ($yy=$rand; $yy<=+$rand+2; $yy++){
for ($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if ($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2; imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c);
}
} //设置文件头;
Header("Content-type: image/JPEG"); //以PNG格式将图像输出到浏览器或文件;
ImagePNG($distortion_im); //销毁一图像,释放与image关联的内存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}function make_rand($length="32"){//验证码文字生成函数
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return $result;
}
//输出调用
$checkcode = make_rand(4);
session_start();//将随机数存入session中
$_SESSION['helloweba_gg']=strtolower($checkcode);
getAuthImage($checkcode);
?>windows的服务器可以. 就是ubuntu 不行检查你的字体文件路径.
ttf 是 windows 的字体文件,你需要安装支持库