繁体   English   中英

如何更改验证码的字体系列并在验证码背景中提供图像?

[英]how to change font family of captcha and give image in background of captcha?

如何更改验证码的字体系列并在验证码的背景中提供图像,请告诉我是否有人知道。 代码如下:

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

看一眼:


我这样使用它(包含的额外文件):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM