2017-07-03 203 views
0

如何更改captcha的字体系列,并在captcha背景中提供图片,请告诉我是否有人知道该问题。代码如下:如何更改captcha的字体系列并在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); 
?> 

回答

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