【问题标题】:Why isn't the PHP imagettftext function working in this case?为什么 PHP imagettftext 函数在这种情况下不起作用?
【发布时间】:2011-12-13 22:01:12
【问题描述】:

谁能告诉我为什么我在尝试创建验证码时不能使用函数 imagettftext?它适用于图像字符串,但字体大小太小,所以我必须使用 imagettftext ...这是 Wamp 的问题还是它是什么?感谢您的宝贵时间!

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);
?>

索引.php:

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

<img src="createanimage.php" />

【问题讨论】:

  • “不能使用”是什么意思?你能发布错误日志吗?

标签: php html image


【解决方案1】:

根据您提供的少量信息,代码最初对我不起作用,我将字体路径从 arial.ttf 更改为 ./arial.ttf。成功了!

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

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

【讨论】:

  • 我只是卡在这一点上,所以我无法继续处理它,但现在当我知道问题时,我可以继续处理它。非常感谢!
  • 谢谢,这也解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 2017-11-26
  • 2010-12-29
  • 1970-01-01
  • 2021-08-05
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多