Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014, British Columbia Institute of Technology |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) |
| 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 1.0.0 |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 39 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter CAPTCHA Helper |
| 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage Helpers |
| 45 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 46 | * @author EllisLab Dev Team |
vkeranov | 6332664 | 2012-07-12 10:51:34 +0300 | [diff] [blame] | 47 | * @link http://codeigniter.com/user_guide/helpers/captcha_helper.html |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 52 | if ( ! function_exists('create_captcha')) |
| 53 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Create CAPTCHA |
| 56 | * |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 57 | * @param array $data data for the CAPTCHA |
| 58 | * @param string $img_path path to create the image in |
| 59 | * @param string $img_url URL to the CAPTCHA image folder |
| 60 | * @param string $font_path server path to font |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 61 | * @return string |
| 62 | */ |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 63 | function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 64 | { |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 65 | $defaults = array( |
| 66 | 'word' => '', |
| 67 | 'img_path' => '', |
| 68 | 'img_url' => '', |
| 69 | 'img_width' => '150', |
| 70 | 'img_height' => '30', |
| 71 | 'font_path' => '', |
| 72 | 'expiration' => 7200, |
| 73 | 'word_length' => 8, |
Preetham | bfa1644 | 2014-11-12 10:26:24 -0500 | [diff] [blame^] | 74 | 'font_size' => 16, |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 75 | 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
| 76 | 'colors' => array( |
| 77 | 'background' => array(255,255,255), |
| 78 | 'border' => array(153,102,102), |
| 79 | 'text' => array(204,153,153), |
| 80 | 'grid' => array(255,182,182) |
| 81 | ) |
| 82 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 83 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 84 | foreach ($defaults as $key => $val) |
| 85 | { |
Andrey Andreev | a720961 | 2012-03-26 21:55:43 +0300 | [diff] [blame] | 86 | if ( ! is_array($data) && empty($$key)) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 87 | { |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 88 | $$key = $val; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 89 | } |
| 90 | else |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 91 | { |
Andrey Andreev | a720961 | 2012-03-26 21:55:43 +0300 | [diff] [blame] | 92 | $$key = isset($data[$key]) ? $data[$key] : $val; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 93 | } |
| 94 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 95 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 96 | if ($img_path === '' OR $img_url === '' |
Andrey Andreev | 382b513 | 2014-02-26 18:41:59 +0200 | [diff] [blame] | 97 | OR ! is_dir($img_path) OR ! is_really_writable($img_path) |
Andrey Andreev | 4f2933d | 2012-01-08 06:49:49 +0200 | [diff] [blame] | 98 | OR ! extension_loaded('gd')) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 99 | { |
| 100 | return FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 103 | // ----------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | // Remove old images |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 105 | // ----------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | |
Michiel Vugteveen | c2659b8 | 2012-03-07 21:34:52 +0100 | [diff] [blame] | 107 | $now = microtime(TRUE); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 108 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 109 | $current_dir = @opendir($img_path); |
Pascal Kriete | 45e3cdf | 2011-02-14 13:26:20 -0500 | [diff] [blame] | 110 | while ($filename = @readdir($current_dir)) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 111 | { |
vlakoff | 5f385d0 | 2012-09-02 23:00:25 +0200 | [diff] [blame] | 112 | if (substr($filename, -4) === '.jpg' && (str_replace('.jpg', '', $filename) + $expiration) < $now) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 113 | { |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 114 | @unlink($img_path.$filename); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 115 | } |
| 116 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 117 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 118 | @closedir($current_dir); |
| 119 | |
| 120 | // ----------------------------------- |
| 121 | // Do we have a "word" yet? |
| 122 | // ----------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 123 | |
Andrey Andreev | 9708855 | 2013-02-08 21:53:20 +0200 | [diff] [blame] | 124 | if (empty($word)) |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 125 | { |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 126 | $word = ''; |
ash | 29ae72d | 2013-04-10 13:59:42 +0100 | [diff] [blame] | 127 | for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < $word_length; $i++) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 128 | { |
ash | 29ae72d | 2013-04-10 13:59:42 +0100 | [diff] [blame] | 129 | $word .= $pool[mt_rand(0, $mt_rand_max)]; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 130 | } |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 131 | } |
Andrey Andreev | 9708855 | 2013-02-08 21:53:20 +0200 | [diff] [blame] | 132 | elseif ( ! is_string($word)) |
| 133 | { |
| 134 | $word = (string) $word; |
| 135 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 136 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 137 | // ----------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 138 | // Determine angle and position |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 139 | // ----------------------------------- |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 140 | $length = strlen($word); |
vlakoff | 3a3d5f6 | 2013-10-17 22:22:16 +0200 | [diff] [blame] | 141 | $angle = ($length >= 6) ? mt_rand(-($length-6), ($length-6)) : 0; |
| 142 | $x_axis = mt_rand(6, (360/$length)-16); |
| 143 | $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 144 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 145 | // Create image |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 146 | // PHP.net recommends imagecreatetruecolor(), but it isn't always available |
Andrey Andreev | 4f2933d | 2012-01-08 06:49:49 +0200 | [diff] [blame] | 147 | $im = function_exists('imagecreatetruecolor') |
| 148 | ? imagecreatetruecolor($img_width, $img_height) |
| 149 | : imagecreate($img_width, $img_height); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 150 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 151 | // ----------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 152 | // Assign colors |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 153 | // ---------------------------------- |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 154 | |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 155 | is_array($colors) OR $colors = $defaults['colors']; |
| 156 | |
Andrey Andreev | 53fd688 | 2013-07-26 02:14:09 +0300 | [diff] [blame] | 157 | foreach (array_keys($defaults['colors']) as $key) |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 158 | { |
| 159 | // Check for a possible missing value |
| 160 | is_array($colors[$key]) OR $colors[$key] = $defaults['colors'][$key]; |
| 161 | $colors[$key] = imagecolorallocate($im, $colors[$key][0], $colors[$key][1], $colors[$key][2]); |
| 162 | } |
| 163 | |
| 164 | // Create the rectangle |
| 165 | ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $colors['background']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 167 | // ----------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 168 | // Create the spiral pattern |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 169 | // ----------------------------------- |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 170 | $theta = 1; |
| 171 | $thetac = 7; |
| 172 | $radius = 16; |
| 173 | $circles = 20; |
| 174 | $points = 32; |
| 175 | |
Andrey Andreev | 3419db1 | 2012-03-26 22:00:07 +0300 | [diff] [blame] | 176 | for ($i = 0, $cp = ($circles * $points) - 1; $i < $cp; $i++) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 177 | { |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 178 | $theta += $thetac; |
| 179 | $rad = $radius * ($i / $points); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 180 | $x = ($rad * cos($theta)) + $x_axis; |
| 181 | $y = ($rad * sin($theta)) + $y_axis; |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 182 | $theta += $thetac; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 183 | $rad1 = $radius * (($i + 1) / $points); |
| 184 | $x1 = ($rad1 * cos($theta)) + $x_axis; |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 185 | $y1 = ($rad1 * sin($theta)) + $y_axis; |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 186 | imageline($im, $x, $y, $x1, $y1, $colors['grid']); |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 187 | $theta -= $thetac; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // ----------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 191 | // Write the text |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 192 | // ----------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 194 | $use_font = ($font_path !== '' && file_exists($font_path) && function_exists('imagettftext')); |
Andrey Andreev | 7203d54 | 2012-03-08 01:42:59 +0200 | [diff] [blame] | 195 | if ($use_font === FALSE) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 196 | { |
Preetham | bfa1644 | 2014-11-12 10:26:24 -0500 | [diff] [blame^] | 197 | ($font_size > 5) && $font_size = 5; |
vlakoff | 3a3d5f6 | 2013-10-17 22:22:16 +0200 | [diff] [blame] | 198 | $x = mt_rand(0, $img_width / ($length / 3)); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 199 | $y = 0; |
| 200 | } |
| 201 | else |
| 202 | { |
Preetham | 83aeef1 | 2014-11-12 08:36:35 -0500 | [diff] [blame] | 203 | ($font_size > 30) && $font_size = 30; |
vlakoff | 3a3d5f6 | 2013-10-17 22:22:16 +0200 | [diff] [blame] | 204 | $x = mt_rand(0, $img_width / ($length / 1.5)); |
Andrey Andreev | 7203d54 | 2012-03-08 01:42:59 +0200 | [diff] [blame] | 205 | $y = $font_size + 2; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 206 | } |
| 207 | |
Andrey Andreev | f1b43d4 | 2012-01-06 14:41:50 +0200 | [diff] [blame] | 208 | for ($i = 0; $i < $length; $i++) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 209 | { |
Andrey Andreev | 7203d54 | 2012-03-08 01:42:59 +0200 | [diff] [blame] | 210 | if ($use_font === FALSE) |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 211 | { |
vlakoff | 3a3d5f6 | 2013-10-17 22:22:16 +0200 | [diff] [blame] | 212 | $y = mt_rand(0 , $img_height / 2); |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 213 | imagestring($im, $font_size, $x, $y, $word[$i], $colors['text']); |
Andrey Andreev | 7203d54 | 2012-03-08 01:42:59 +0200 | [diff] [blame] | 214 | $x += ($font_size * 2); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 215 | } |
| 216 | else |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 217 | { |
vlakoff | 3a3d5f6 | 2013-10-17 22:22:16 +0200 | [diff] [blame] | 218 | $y = mt_rand($img_height / 2, $img_height - 3); |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 219 | imagettftext($im, $font_size, $angle, $x, $y, $colors['text'], $font_path, $word[$i]); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 220 | $x += $font_size; |
| 221 | } |
| 222 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 223 | |
Andrey Andreev | 63a2100 | 2012-01-19 15:13:32 +0200 | [diff] [blame] | 224 | // Create the border |
Andrey Andreev | 8963f40 | 2013-07-18 16:02:47 +0300 | [diff] [blame] | 225 | imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $colors['border']); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 226 | |
| 227 | // ----------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 228 | // Generate the image |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 229 | // ----------------------------------- |
egig | 225f53b | 2014-05-08 10:34:35 +0700 | [diff] [blame] | 230 | $img_url = rtrim($img_url, '/').'/'; |
ET-NiK | 6854f87 | 2014-08-08 18:43:02 +0400 | [diff] [blame] | 231 | |
Andrey Andreev | 09546ed | 2014-08-11 00:11:36 +0300 | [diff] [blame] | 232 | if (function_exists('imagejpeg')) |
ET-NiK | 6854f87 | 2014-08-08 18:43:02 +0400 | [diff] [blame] | 233 | { |
| 234 | $img_filename = $now.'.jpg'; |
Andrey Andreev | 09546ed | 2014-08-11 00:11:36 +0300 | [diff] [blame] | 235 | imagejpeg($im, $img_path.$img_filename); |
ET-NiK | 6854f87 | 2014-08-08 18:43:02 +0400 | [diff] [blame] | 236 | } |
Andrey Andreev | 09546ed | 2014-08-11 00:11:36 +0300 | [diff] [blame] | 237 | elseif (function_exists('imagepng')) |
ET-NiK | 6854f87 | 2014-08-08 18:43:02 +0400 | [diff] [blame] | 238 | { |
| 239 | $img_filename = $now.'.png'; |
Andrey Andreev | 09546ed | 2014-08-11 00:11:36 +0300 | [diff] [blame] | 240 | imagepng($im, $img_path.$img_filename); |
ET-NiK | 6854f87 | 2014-08-08 18:43:02 +0400 | [diff] [blame] | 241 | } |
| 242 | else |
| 243 | { |
| 244 | return FALSE; |
| 245 | } |
| 246 | |
Andrey Andreev | 72b4b3c | 2013-10-21 14:44:57 +0300 | [diff] [blame] | 247 | $img = '<img src="'.$img_url.$img_filename.'" style="width: '.$img_width.'; height: '.$img_height .'; border: 0;" alt=" " />'; |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 248 | ImageDestroy($im); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 249 | |
Andrey Andreev | 72b4b3c | 2013-10-21 14:44:57 +0300 | [diff] [blame] | 250 | return array('word' => $word, 'time' => $now, 'image' => $img, 'filename' => $img_filename); |
Derek Jones | b41032d | 2010-03-05 11:22:45 -0600 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Derek Jones | 1c73f4e | 2010-03-05 11:27:41 -0600 | [diff] [blame] | 254 | /* End of file captcha_helper.php */ |
egig | f039c9f | 2014-05-09 03:10:05 +0700 | [diff] [blame] | 255 | /* Location: ./system/helpers/captcha_helper.php */ |