imagejpeg();不在主机服务器上生成图像,在localhost上正常工作

编程入门 行业动态 更新时间:2024-10-23 14:27:37
本文介绍了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上正常工作

本文发布于:2023-11-01 02:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   器上   主机   工作   imagejpeg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!