如何更改验证码的字体系列并在验证码的背景中提供图像请告诉我是否有人知道。代码如下:
<?php
session_start();
$change_time = md5(microtime());
$get_value = substr($change_time, 0, 6);
$_SESSION['value'] = $get_value;
$create_image = imagecreate(100, 30);
imagecolorallocate($create_image, 51, 112, 183);
$text_color = imagecolorallocate($create_image, 255, 255, 255);
imagestring($create_image, 50, 15, 7, $get_value, $text_color);
header('Content:image/jpeg');
imagejpeg($create_image);
?>
答案 0 :(得分:1)
看看:
我像这样使用它(包括额外的文件):
session_name("page_session_name");
session_start();
header("Content-Type: image/png"); // Sets the Content of this file to an PNG-Image
$ttf = "./franconi.ttf"; // font path
$_SESSION["captcha_id"] = ""; // Clears the old value
$rnd = mt_rand(30000,90000); // Generates a random number between 30000 and 90000
$_SESSION["captcha_id"] = $rnd; // Sets the value of the session
$bild = imagecreatefromgif("bg.gif"); // Creates a new image from background file
$textColor = imagecolorallocate($bild, 255, 255, 255); // Sets white text color
imagettftext($bild, 11, 10, 5, 20, $textColor, $ttf, $_SESSION["captcha_id"]);
ImagePNG($bild); // Output for the generated image
包括这样:
<img src="./path_to/captcha.php" title="Captcha" height="50" width="100"/>