【发布时间】:2014-05-09 18:55:10
【问题描述】:
我正在尝试在 php 中制作验证码。这是我的代码:
$amountChars = 5;
$randString = substr(md5(uniqid()), 0, $amountChars);
$img = imagecreatfromjpeg("noise.jpg");
imageantialias($img, true);
$x = 20;
$y = 35;
$deltaX = 40;
for($i = 0; $i < $amountChars; $i++){
$size = rand(18, 28);
$r = rand(0,152);
$g = rand(0,152);
$b = rand(0,152);
$color = imagecolorallocate($img, $r, $g, $b);
$angle = -30 + rand(0, 60);
imagettftext($img, $size, $angle, $x, $y, $color, "Blokletters-Balpen.ttf", $randString{$i});
$x += $deltaX;
}
header("Content-Type: image/png");
imagePNG($img);
问题是,它不起作用。我搜索了一个多小时的错误,但没有成功。
【问题讨论】:
-
请解释什么不起作用。 (以及第纳尔是多少)
-
图片需要在自己的页面上渲染。
-
为什么要混合 PNG 和 JPEG? (imagecreatefromjpeg, and later imagePNG) 你确定允许吗?如果没有,您是否尝试过将基本图像转换为 PNG 并使用 imagecreatefrompng ?
-
Placeholders_in_use 我有... nl-x 图片不显示。跨度>
-
image_capcha.php是否甚至将输出呈现到文件中?那是你应该首先尝试的。如果可行,则再次检查 PHP 代码以查看如何将其直接呈现为图像SRC标记。