source: extensions/CryptograPHP/securimage/securimage_show.php @ 28151

Last change on this file since 28151 was 26554, checked in by mistic100, 11 years ago

update Securimage to 3.5.1, new font, new preset, allow to use backgrounds

File size: 4.0 KB
Line 
1<?php
2/**
3 * Project:     Securimage: A PHP class for creating and managing form CAPTCHA images
4 * File:        securimage_show.php
5 *
6 * Copyright (c) 2011, Drew Phillips
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 *  - Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  - Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Any modifications to the library should be indicated clearly in the source code
31 * to inform users that the changes are not a part of the original software.
32 *
33 * If you found this script useful, please take a quick moment to rate it.
34 * http://www.hotscripts.com/rate/49400.html  Thanks.
35 *
36 * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
37 * @link http://www.phpcaptcha.org/latest.zip Download Latest Version
38 * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
39 * @copyright 2011 Drew Phillips
40 * @author Drew Phillips <drew@drew-phillips.com>
41 * @version 3.0 (October 2011)
42 * @package Securimage
43 *
44 */
45
46define('PHPWG_ROOT_PATH','../../../');
47include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
48
49
50// randomize colors
51function randomColor()
52{
53  mt_srand((double)microtime()*1000000);
54  $c = null;
55  while(strlen($c)<6)
56  {
57      $c .= sprintf("%02X", mt_rand(0, 255));
58  }
59  return $c;
60}
61
62foreach (array('bg_color','text_color','line_color','noise_color') as $color)
63{
64  if ($conf['cryptographp'][$color] == 'random') $conf['cryptographp'][$color] = randomColor();
65}
66
67
68require_once dirname(__FILE__) . '/securimage.php';
69$img = new securimage();
70
71$img->ttf_file        = './fonts/'.$conf['cryptographp']['ttf_file'].'.ttf';
72$img->captcha_type    = ($conf['cryptographp']['captcha_type'] == 'string') ? Securimage::SI_CAPTCHA_STRING : Securimage::SI_CAPTCHA_MATHEMATIC;
73// $img->case_sensitive  = get_boolean($conf['cryptographp']['case_sensitive']);
74$img->image_width     = $conf['cryptographp']['width']; 
75$img->image_height    = $conf['cryptographp']['height'];
76$img->perturbation    = $conf['cryptographp']['perturbation'];
77$img->text_color      = new Securimage_Color('#'.$conf['cryptographp']['text_color']); 
78$img->num_lines       = $conf['cryptographp']['num_lines'];
79$img->line_color      = new Securimage_Color('#'.$conf['cryptographp']['line_color']);
80$img->noise_level     = $conf['cryptographp']['noise_level'];
81$img->noise_color     = new Securimage_Color('#'.$conf['cryptographp']['noise_color']);
82$img->code_length     = $conf['cryptographp']['code_length'];
83
84if ($conf['cryptographp']['background'] == 'image')
85{
86  if ($conf['cryptographp']['bg_image'] == 'random')
87  {
88    $img->background_directory = realpath(CRYPTO_PATH . 'securimage/backgrounds/');
89    $img->show();
90  }
91  else
92  {
93    $img->show(realpath(CRYPTO_PATH . 'securimage/backgrounds/' . $conf['cryptographp']['bg_image']));
94  }
95}
96else
97{
98  $img->image_bg_color  = new Securimage_Color('#'.$conf['cryptographp']['bg_color']);
99  $img->show();
100}
Note: See TracBrowser for help on using the repository browser.