php GD验证码图像未在Mac上显示

时间:2011-05-13 09:27:03

标签: php macos gd captcha

我正在为表单使用简单的验证码系统。在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()!

有什么建议吗?

提前致谢。

莫罗

2 个答案:

答案 0 :(得分:2)

如果错误为Fatal error: Call to undefined function imagettftext(),则表示未安装GD模块。

顺便提一下,请更新您的问题,说明您要做的事情和地点。 “在Mac上”是什么意思?您使用的是哪种操作系统?哪个Web服务器?哪个版本?哪个PHP版本?等等...

答案 1 :(得分:0)

Snow Leopard上的PHP 5.3.x缺少ttf(TrueType)模块

相关问题