2011-05-13 30 views
0

我正在使用一個簡單的驗證碼系統的窗體。在Windows上運行良好,但不在Mac上顯示。在兩個系統中啓用DG,我已經檢查過phpinfo()。php GD captcha圖像不顯示在Mac上

<?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()!

有什麼建議嗎?

在此先感謝。

莫羅

+1

加入使用error_reporting(E_ALL); ini_set('display_errors','On');在您的PHP腳本的開頭,查看可能的錯誤。我看到兩個可能的問題:它無法找到字體文件或標題的東西使Windows上的問題 – strauberry 2011-05-13 09:28:52

+1

你是什麼意思「在Mac上」?在Mac服務器上?在Mac瀏覽器上?如果您嘗試直接訪問CAPTCHA圖像會發生什麼情況,您會得到什麼信息? – 2011-05-13 09:28:55

+0

@strauberry我添加了錯誤報告,我得到了這個:致命錯誤:調用未定義函數imagettftext()在/Users/.../captcha.php在第26行。什麼樣的錯誤是?我如何解決它?謝謝 – Mauro74 2011-05-13 09:33:19

回答

2

如果錯誤是Fatal error: Call to undefined function imagettftext()這意味着GD模塊未安裝。

順便說一句,請更新您的問題,澄清你想要做什麼和在哪裏。 「在Mac上」是什麼意思?你正在使用哪種操作系統?哪個網頁服務器?哪個版本?哪個PHP版本?等等...

+0

這很奇怪,因爲如果我導航到函數的定義,它會將我帶到GD庫中的imagettftext()! – Mauro74 2011-05-13 09:52:52

+0

你「導航」?怎麼樣?哪裏?在你的IDE中?您的IDE不是Web服務器,如果您在IDE中看到某些內容,則這並不表示它也可以在Web服務器上使用。順便說一句,你錯過了指定你正在使用的Web服務器(和版本)。 – Albireo 2011-05-13 09:57:11

+0

是的我的ide。但我已經運行的phpinfo,並表明GD安裝:使用Apache 2.2 – Mauro74 2011-05-13 09:58:54

0

雪豹PHP 5.3.x缺少TTF(TrueType字體)模塊