Вход Регистрация
Файл: wboard/source/system/controller/captcha.php
Строк: 49
<?php

/**
 * Wboard
 * Captcha
 * @author Screamer
 * @copyright 2013
 */

class Module_Captcha extends Module
{

    
/**
     * Display image and set code to session ($_SESSION['captcha'])
     * @return (void)
     */
    
public function index()
    {
        
header("Content-type: image/png");
        
$this->display = FALSE;
        
$data = $this->render();
        
$_SESSION['captcha'] = $data[0];
        
imagepng($data[1]);
    }

    
/**
     * Generate code. Create image
     * @return (array) [code], [image]
     */
    
protected function render()
    {
        
// List of symbols
        
$alphabet = '012345789';
        
$alphabet = preg_split('//u', $alphabet, -1, PREG_SPLIT_NO_EMPTY);
        
$a_length = count($alphabet) - 1;
        
// Length of string
        
$max_len = rand(3, 6);
        
// Load font
        
$font = $this->path . 'files' . DIRECTORY_SEPARATOR . 'consola.ttf';
        
// Create image
        
$image = imagecreatetruecolor(160, 40);
        
// Set background
        
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
        
// Draw text
        
$code = '';
        for (
$i = 0, $x = 15; $i < $max_len; $i++, $x += 14) {
            
$color = imagecolorallocate($image, rand(10, 50), rand(10, 50), rand(10, 50));
            
$symbol = $alphabet[rand(0, $a_length)];
            
$code .= $symbol;
            
imagefttext($image, rand(18, 20), rand(-30, 30), $x, rand(20, 30), $color, $font, $symbol);
        }
        
// Noise
        
for ($i = 0, $x = 15; $i < $max_len; $i++, $x += 18) {
            
$color = imagecolorallocate($image, rand(200, 220), rand(200, 220), rand(200, 220));
            
imagefttext($image, rand(18, 20), rand(-30, 30), $x, rand(20, 30), $color, $font, $alphabet[rand(0, $a_length)]);
        }
        return array(
$code, $image);
    }

}
Онлайн: 2
Реклама