php GD captcha image not showing on Mac
I'm using a simple cap开发者_开发问答tcha 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
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...
PHP 5.3.x on Snow Leopard is missing the ttf (TrueType) module
精彩评论