imagejpeg();不在主机服务器上生成图像,在localhost上正常工作 [英] imagejpeg(); not generating image on host server , working fine on localhost

查看:207
本文介绍了imagejpeg();不在主机服务器上生成图像,在localhost上正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,它应该生成一个随机数的验证码图像,它在localhost上正常工作但在我的托管上没有工作,任何人都可以帮忙吗?谁能告诉我哪里出错了?

I have this code which is supposed to generate a captcha image of random number , it's working fine on localhost but not on my hosting, Can anyone help please? Can someone tell me where am i going wrong ?

         <?php
 session_start();
header('Content-type: image/jpeg');

 $text= $_SESSION['secure'];

 $font_size =30;
 $image_width= 110;
 $image_height=40;

 $image=imagecreate($image_width,$image_height);
 imagecolorallocate($image, 255, 255, 255);
 $text_color = imagecolorallocate($image, 0, 0, 0);


 for($x=1; $x<=30; $x++){
$x1 = rand(1,100);
$x2 = rand(1,100);
$y1 = rand(1,100);
$y2 = rand(1,100);
 imageline($image, $x1, $x2, $y1, $y2, $text_color);
}

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);
?>

然后我将包含上述代码的文件包含在一个新的html文件中,其中我有我的表单并调用这样的图像:

And then i include the file that contains the above code in a new html file where i have my form and calling the image like this :

 <img src="generate.php"/>


推荐答案

使用字符串测试脚本你好,它的工作原理

Tested your script with string hello and it works

我非常肯定问题是 PHP 无法找到字体..尝试使用完整系统路径

Am very sure the issue is that PHP can not located the font .. try using full system path

尝试

$font = dirname ( __FILE__ ) . "/verdana.ttf" ;
if(!is_file($font))
{
    die("Missing Font");
}

这篇关于imagejpeg();不在主机服务器上生成图像,在localhost上正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆