为什么PHP imagettftext函数在这种情况下不起作用?


Why isn't the PHP imagettftext function working in this case?

谁能告诉我为什么我不能使用imagettftext函数当我试图创建一个验证码?它工作得很好与imagestrings,但字体大小是小,所以我不得不使用imagettftext…这是万普的问题还是别的什么?谢谢你的时间!

PHP代码(目前):

<?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" />

从你给出的一点信息来看,代码最初不适合我,我将字体路径从arial.ttf更改为./arial.ttf。它工作!

您的代码的精确副本:http://tekinozbek.net/so_imagettftext.php

小心一些垃圾邮件发送者使用图像分析来识别文本路径并确定CAPTCHA图像!我当然建议你使用reCAPTCHA这样的东西来更好地防止垃圾邮件。