Can anyone tell me why I can’t use the function imagettftext when I’m trying to create a captcha? It works fine with imagestrings, but the font-size is to small so I have to use imagettftext… Is this a problem with Wamp or what is it? Thanks for your time!
PHP code(so far):
<?php
session_start();
header("Content-Type: image/png");
$text = $_SESSION['secure'];
$font_size = 30;
$image_width = 200;
$image_height = 40;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, $font_size, 0, 15, 30, $text_color, 'arial.ttf', $text);
imagepng($image);
?>
Index.php:
<?php
session_start();
$_SESSION['secure'] = rand(1000,9999);
?>
<img src="createanimage.php" />
From what little info you’ve given, the code initially didn’t work for me, I changed the font path from
arial.ttfto./arial.ttf. It worked!An exact replica of your code: http://tekinozbek.net/so_imagettftext.php
Beware some spammers use image analysis to recognize text paths and determine the CAPTCHA image! I would certainly suggest you use something like reCAPTCHA for better protection against spam.