为什么在这种情况下PHP imagettftext函数不起作用? [英] Why isn't the PHP imagettftext function working in this case?

查看:1157
本文介绍了为什么在这种情况下PHP imagettftext函数不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我为什么我在创建验证码时无法使用函数imagettftext?它适用于图像字符,但字体大小很小,所以我必须使用imagettftext ...这是一个Wamp的问题或它是什么?感谢您的时间!

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代码(至今):

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:

Index.php:

<?php
session_start();
$_SESSION['secure'] = rand(1000,9999);
?>

<img src="createanimage.php" />


推荐答案

最初没有为我工作,我改变了从 arial.ttf ./ arial.ttf 的字体路径。它的工作!

From what little info you've given, the code initially didn't work for me, I changed the font path from arial.ttf to ./arial.ttf. It worked!

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

An exact replica of your code: http://tekinozbek.net/so_imagettftext.php

谨防一些垃圾邮件发送者使用图像分析来识别文本路径并确定验证码图像!我肯定会建议您使用 reCAPTCHA 之类的内容来更好地防范垃圾邮件。

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.

这篇关于为什么在这种情况下PHP imagettftext函数不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆