php GD 验证码图像在 Mac 上不显示
我正在使用一个简单的验证码系统作为表单。在 Windows 上工作正常,但在 Mac 上不显示。在这两个系统中,DG 均已启用,我已使用 phpinfo() 检查过。
<?php
session_start();
// generate random number and store in session
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
//generate image
$im = imagecreatetruecolor(90, 32);
//colors:
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
//path to font:
$font = 'fonts/rock-webfont.ttf';
//draw text:
//imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnr);
//imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnr);
imagettftext($im, 24, 0, 12, 26, $grey, $font, $randomnr);
imagettftext($im, 24, 0, 8, 28, $white, $font, $randomnr);
// prevent client side caching
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//send image to browser
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>
更新:我正在使用安装了 PHP 版本 5.3.3 的 OS X Snow Leopard。我现在启用了错误报告,并看到此错误:调用未定义的函数 imagettftext()。这很奇怪,因为如果我导航到函数的定义,它会将我带到 GD 库中的 imagettftext()!
有什么建议吗?
提前致谢。
毛罗
I'm using a simple captcha system for a form. Works fine on Windows but it not showing on Mac. In both systems DG is enabled, I've checked with phpinfo().
<?php
session_start();
// generate random number and store in session
$randomnr = rand(1000, 9999);
$_SESSION['randomnr2'] = md5($randomnr);
//generate image
$im = imagecreatetruecolor(90, 32);
//colors:
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 200, 35, $black);
//path to font:
$font = 'fonts/rock-webfont.ttf';
//draw text:
//imagettftext($im, 35, 0, 22, 24, $grey, $font, $randomnr);
//imagettftext($im, 35, 0, 15, 26, $white, $font, $randomnr);
imagettftext($im, 24, 0, 12, 26, $grey, $font, $randomnr);
imagettftext($im, 24, 0, 8, 28, $white, $font, $randomnr);
// prevent client side caching
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//send image to browser
header ("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
?>
UPDATE: I'm using OS X Snow Leopard with PHP Version 5.3.3 installed. I now enabled error reporting and I see this error: Call to undefined function imagettftext(). This is strange because if I navigate to the definition of the function it takes me to the imagettftext() in the GD library!
Any suggestion?
Thanks in advance.
Mauro
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果错误是
致命错误:调用未定义的函数 imagettftext()
,则表示未安装 GD 模块。顺便说一句,请更新您的问题,明确您想要做什么以及在哪里做。 “在 Mac 上”是什么意思?您使用哪个操作系统?哪个网络服务器?哪个版本?哪个 PHP 版本?等等...
If the error is
Fatal error: Call to undefined function imagettftext()
it means the GD module is not installed.By the way, please update your question clarifying what and where you're trying to do. What does "on a Mac" means? Which operating system are you using? Which web sever? Which version? Which PHP version? And so on...
Snow Leopard 上的 PHP 5.3.x 缺少 ttf (TrueType) 模块
PHP 5.3.x on Snow Leopard is missing the ttf (TrueType) module