Project

General

Profile

1
<?php
2

    
3
// $Id: calc_image.php 2 2017-07-02 15:14:29Z Manuela $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname(dirname((__DIR__)))).'/config.php' ); }
27
require_once(WB_PATH.'/include/captcha/captcha.php');
28

    
29
if(!isset($_SESSION['captcha_time']))
30
    exit;
31
//unset($_SESSION['captcha_time']);
32

    
33
// Captcha
34
$sec_id = '';
35
if(isset($_GET['s'])) $sec_id = $_GET['s'];
36
$_SESSION['captcha'.$sec_id] = '';
37
mt_srand((double)microtime()*1000000);
38
$n = mt_rand(1,3);
39
switch ($n) {
40
    case 1:
41
        $x = mt_rand(1,9);
42
        $y = mt_rand(1,9);
43
        $_SESSION['captcha'.$sec_id] = $x + $y;
44
        $cap = "$x+$y"; 
45
        break; 
46
    case 2:
47
        $x = mt_rand(10,20);
48
        $y = mt_rand(1,9);
49
        $_SESSION['captcha'.$sec_id] = $x - $y; 
50
        $cap = "$x-$y"; 
51
        break;
52
    case 3:
53
        $x = mt_rand(2,10);
54
        $y = mt_rand(2,5);
55
        $_SESSION['captcha'.$sec_id] = $x * $y; 
56
        $cap = "$x*$y"; 
57
        break;
58
}
59

    
60
// create reload-image
61
$reload = ImageCreateFromPNG(WB_PATH.'/include/captcha/reload_120_30.png'); // reload-overlay
62

    
63
$image = imagecreate(120, 30);
64

    
65
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
66
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
67
$textcolor = imagecolorallocate($image, 0x30, 0x30, 0x30);
68

    
69
for($i = 0; $i < 30; $i++) {
70
    $x1 = mt_rand(0,120);
71
    $y1 = mt_rand(0,30);
72
    $x2 = mt_rand(0,120);
73
    $y2 = mt_rand(0,30);
74
    imageline($image, $x1, $y1, $x2, $y2 , $gray);  
75
}
76

    
77
$Fontfile = ( dirname(__DIR__).'/fonts/LLBd_cond.ttf');
78
$angle = 0;
79
$ttfsize = 25; // fontsize
80
$x =  15;
81
$l = strlen($cap);
82
for($i = 0; $i < $l; $i++) {
83
      $x = $x + mt_rand(10 , 25);
84
      $y = mt_rand(18, 23);
85
      $angle = mt_rand(-2, 2);
86
      $res = imagettftext ($image, $ttfsize, $angle, $x, $y, $textcolor, $Fontfile, substr($cap, $i, 1) );
87
//    $fnt = mt_rand(5,7);
88
//    imagestring($image, $fnt, $x, $y, substr($cap, $i, 1), $textcolor); 
89
}
90

    
91
imagealphablending($reload, TRUE);
92
imagesavealpha($reload, TRUE);
93

    
94
// overlay
95
imagecopy($reload, $image, 0,0,0,0, 120,40);
96
imagedestroy($image);
97
$image = $reload;
98

    
99
captcha_header();
100
imagepng($image);
101
imagedestroy($image);
102

    
(1-1/13)