blob: d3a832415a980705e6617577ff9b2a16e46eb68e [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Eric Barnesb1673362011-12-05 22:05:38 -05008 *
Andrey Andreev125ef472016-01-11 12:33:00 +02009 * Copyright (c) 2014 - 2016, British Columbia Institute of Technology
Eric Barnesb1673362011-12-05 22:05:38 -050010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * 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 Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * 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
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreev125ef472016-01-11 12:33:00 +020032 * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
Andrey Andreevbd202c92016-01-11 12:50:18 +020034 * @link https://codeigniter.com
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020035 * @since Version 1.0.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
41 * Image Manipulation class
42 *
43 * @package CodeIgniter
44 * @subpackage Libraries
45 * @category Image_lib
Derek Jonesf4a4bd82011-10-20 12:18:42 -050046 * @author EllisLab Dev Team
Andrey Andreevbd202c92016-01-11 12:50:18 +020047 * @link https://codeigniter.com/user_guide/libraries/image_lib.html
Derek Allard2067d1a2008-11-13 22:59:24 +000048 */
49class CI_Image_lib {
50
Timothy Warrenb8e62852012-04-26 18:40:54 -040051 /**
52 * PHP extension/library to use for image manipulation
Andrey Andreev56454792012-05-17 14:32:19 +030053 * Can be: imagemagick, netpbm, gd, gd2
Timothy Warrenb8e62852012-04-26 18:40:54 -040054 *
55 * @var string
56 */
57 public $image_library = 'gd2';
Andrey Andreev56454792012-05-17 14:32:19 +030058
Timothy Warrenb8e62852012-04-26 18:40:54 -040059 /**
60 * Path to the graphic library (if applicable)
61 *
62 * @var string
63 */
Andrey Andreev3a459572011-12-21 11:23:11 +020064 public $library_path = '';
Andrey Andreev56454792012-05-17 14:32:19 +030065
Timothy Warrenb8e62852012-04-26 18:40:54 -040066 /**
67 * Whether to send to browser or write to disk
68 *
69 * @var bool
70 */
71 public $dynamic_output = FALSE;
Andrey Andreev56454792012-05-17 14:32:19 +030072
Timothy Warrenb8e62852012-04-26 18:40:54 -040073 /**
74 * Path to original image
75 *
76 * @var string
77 */
Andrey Andreev3a459572011-12-21 11:23:11 +020078 public $source_image = '';
Andrey Andreev56454792012-05-17 14:32:19 +030079
Timothy Warrenb8e62852012-04-26 18:40:54 -040080 /**
81 * Path to the modified image
82 *
83 * @var string
84 */
Andrey Andreev56454792012-05-17 14:32:19 +030085 public $new_image = '';
86
Timothy Warrenb8e62852012-04-26 18:40:54 -040087 /**
88 * Image width
89 *
90 * @var int
91 */
Andrey Andreev56454792012-05-17 14:32:19 +030092 public $width = '';
93
Timothy Warrenb8e62852012-04-26 18:40:54 -040094 /**
95 * Image height
96 *
97 * @var int
98 */
Andrey Andreev56454792012-05-17 14:32:19 +030099 public $height = '';
100
Timothy Warrenb8e62852012-04-26 18:40:54 -0400101 /**
102 * Quality percentage of new image
103 *
104 * @var int
105 */
Andrey Andreev56454792012-05-17 14:32:19 +0300106 public $quality = 90;
107
Timothy Warrenb8e62852012-04-26 18:40:54 -0400108 /**
109 * Whether to create a thumbnail
110 *
111 * @var bool
112 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200113 public $create_thumb = FALSE;
Andrey Andreev56454792012-05-17 14:32:19 +0300114
Timothy Warrenb8e62852012-04-26 18:40:54 -0400115 /**
116 * String to add to thumbnail version of image
117 *
118 * @var string
119 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200120 public $thumb_marker = '_thumb';
Andrey Andreev56454792012-05-17 14:32:19 +0300121
Timothy Warrenb8e62852012-04-26 18:40:54 -0400122 /**
123 * Whether to maintain aspect ratio when resizing or use hard values
124 *
125 * @var bool
126 */
127 public $maintain_ratio = TRUE;
Andrey Andreev56454792012-05-17 14:32:19 +0300128
Timothy Warrenb8e62852012-04-26 18:40:54 -0400129 /**
130 * auto, height, or width. Determines what to use as the master dimension
131 *
132 * @var string
133 */
Andrey Andreev56454792012-05-17 14:32:19 +0300134 public $master_dim = 'auto';
135
Timothy Warrenb8e62852012-04-26 18:40:54 -0400136 /**
137 * Angle at to rotate image
138 *
139 * @var string
140 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200141 public $rotation_angle = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300142
Timothy Warrenb8e62852012-04-26 18:40:54 -0400143 /**
144 * X Coordinate for manipulation of the current image
145 *
146 * @var int
147 */
Andrey Andreev56454792012-05-17 14:32:19 +0300148 public $x_axis = '';
149
Timothy Warrenb8e62852012-04-26 18:40:54 -0400150 /**
151 * Y Coordinate for manipulation of the current image
152 *
153 * @var int
154 */
Andrey Andreev56454792012-05-17 14:32:19 +0300155 public $y_axis = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000156
Timothy Warrenb8e62852012-04-26 18:40:54 -0400157 // --------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000158 // Watermark Vars
Timothy Warrenb8e62852012-04-26 18:40:54 -0400159 // --------------------------------------------------------------------------
Andrey Andreev56454792012-05-17 14:32:19 +0300160
Timothy Warrenb8e62852012-04-26 18:40:54 -0400161 /**
162 * Watermark text if graphic is not used
163 *
164 * @var string
165 */
166 public $wm_text = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300167
Timothy Warrenb8e62852012-04-26 18:40:54 -0400168 /**
169 * Type of watermarking. Options: text/overlay
170 *
171 * @var string
172 */
173 public $wm_type = 'text';
Andrey Andreev56454792012-05-17 14:32:19 +0300174
Timothy Warrenb8e62852012-04-26 18:40:54 -0400175 /**
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400176 * Default transparency for watermark
Andrey Andreev56454792012-05-17 14:32:19 +0300177 *
Timothy Warrenb8e62852012-04-26 18:40:54 -0400178 * @var int
179 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200180 public $wm_x_transp = 4;
Andrey Andreev56454792012-05-17 14:32:19 +0300181
Timothy Warrenb8e62852012-04-26 18:40:54 -0400182 /**
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400183 * Default transparency for watermark
184 *
Timothy Warrenb8e62852012-04-26 18:40:54 -0400185 * @var int
186 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200187 public $wm_y_transp = 4;
Andrey Andreev56454792012-05-17 14:32:19 +0300188
Timothy Warrenb8e62852012-04-26 18:40:54 -0400189 /**
190 * Watermark image path
Andrey Andreev56454792012-05-17 14:32:19 +0300191 *
Timothy Warrenb8e62852012-04-26 18:40:54 -0400192 * @var string
193 */
Andrey Andreev56454792012-05-17 14:32:19 +0300194 public $wm_overlay_path = '';
195
Timothy Warrenb8e62852012-04-26 18:40:54 -0400196 /**
197 * TT font
198 *
199 * @var string
200 */
201 public $wm_font_path = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300202
Timothy Warrenb8e62852012-04-26 18:40:54 -0400203 /**
204 * Font size (different versions of GD will either use points or pixels)
205 *
206 * @var int
207 */
208 public $wm_font_size = 17;
Andrey Andreev56454792012-05-17 14:32:19 +0300209
Timothy Warrenb8e62852012-04-26 18:40:54 -0400210 /**
211 * Vertical alignment: T M B
212 *
213 * @var string
214 */
215 public $wm_vrt_alignment = 'B';
Andrey Andreev56454792012-05-17 14:32:19 +0300216
Timothy Warrenb8e62852012-04-26 18:40:54 -0400217 /**
218 * Horizontal alignment: L R C
219 *
220 * @var string
221 */
222 public $wm_hor_alignment = 'C';
Andrey Andreev56454792012-05-17 14:32:19 +0300223
Timothy Warrenb8e62852012-04-26 18:40:54 -0400224 /**
225 * Padding around text
226 *
227 * @var int
228 */
229 public $wm_padding = 0;
Andrey Andreev56454792012-05-17 14:32:19 +0300230
Timothy Warrenb8e62852012-04-26 18:40:54 -0400231 /**
232 * Lets you push text to the right
233 *
234 * @var int
235 */
236 public $wm_hor_offset = 0;
Andrey Andreev56454792012-05-17 14:32:19 +0300237
Timothy Warrenb8e62852012-04-26 18:40:54 -0400238 /**
239 * Lets you push text down
240 *
241 * @var int
242 */
243 public $wm_vrt_offset = 0;
Andrey Andreev56454792012-05-17 14:32:19 +0300244
Timothy Warrenb8e62852012-04-26 18:40:54 -0400245 /**
246 * Text color
247 *
248 * @var string
249 */
Andrey Andreev56454792012-05-17 14:32:19 +0300250 protected $wm_font_color = '#ffffff';
251
Timothy Warrenb8e62852012-04-26 18:40:54 -0400252 /**
253 * Dropshadow color
254 *
255 * @var string
256 */
Andrey Andreev56454792012-05-17 14:32:19 +0300257 protected $wm_shadow_color = '';
258
Timothy Warrenb8e62852012-04-26 18:40:54 -0400259 /**
260 * Dropshadow distance
261 *
262 * @var int
263 */
264 public $wm_shadow_distance = 2;
Andrey Andreev56454792012-05-17 14:32:19 +0300265
Timothy Warrenb8e62852012-04-26 18:40:54 -0400266 /**
267 * Image opacity: 1 - 100 Only works with image
268 *
269 * @var int
270 */
Andrey Andreev56454792012-05-17 14:32:19 +0300271 public $wm_opacity = 50;
Derek Allard2067d1a2008-11-13 22:59:24 +0000272
Timothy Warrenb8e62852012-04-26 18:40:54 -0400273 // --------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 // Private Vars
Timothy Warrenb8e62852012-04-26 18:40:54 -0400275 // --------------------------------------------------------------------------
Andrey Andreev56454792012-05-17 14:32:19 +0300276
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400277 /**
278 * Source image folder
279 *
280 * @var string
281 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200282 public $source_folder = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300283
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400284 /**
285 * Destination image folder
286 *
287 * @var string
288 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200289 public $dest_folder = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300290
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400291 /**
292 * Image mime-type
293 *
294 * @var string
295 */
Andrey Andreev56454792012-05-17 14:32:19 +0300296 public $mime_type = '';
297
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400298 /**
Andrey Andreev56454792012-05-17 14:32:19 +0300299 * Original image width
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400300 *
301 * @var int
302 */
Andrey Andreev56454792012-05-17 14:32:19 +0300303 public $orig_width = '';
304
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400305 /**
306 * Original image height
307 *
308 * @var int
309 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200310 public $orig_height = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300311
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400312 /**
313 * Image format
Andrey Andreev56454792012-05-17 14:32:19 +0300314 *
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400315 * @var string
316 */
Andrey Andreev56454792012-05-17 14:32:19 +0300317 public $image_type = '';
318
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400319 /**
320 * Size of current image
321 *
322 * @var string
323 */
Andrey Andreev56454792012-05-17 14:32:19 +0300324 public $size_str = '';
325
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400326 /**
327 * Full path to source image
328 *
329 * @var string
330 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200331 public $full_src_path = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300332
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400333 /**
334 * Full path to destination image
335 *
336 * @var string
337 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200338 public $full_dst_path = '';
Andrey Andreev56454792012-05-17 14:32:19 +0300339
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400340 /**
Andrey Andreev45965742014-08-27 20:40:11 +0300341 * File permissions
342 *
343 * @var int
344 */
345 public $file_permissions = 0644;
346
347 /**
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400348 * Name of function to create image
349 *
350 * @var string
351 */
Andrey Andreev56454792012-05-17 14:32:19 +0300352 public $create_fnc = 'imagecreatetruecolor';
353
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400354 /**
355 * Name of function to copy image
356 *
357 * @var string
358 */
Andrey Andreev56454792012-05-17 14:32:19 +0300359 public $copy_fnc = 'imagecopyresampled';
360
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400361 /**
362 * Error messages
363 *
364 * @var array
365 */
Andrey Andreev56454792012-05-17 14:32:19 +0300366 public $error_msg = array();
367
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400368 /**
369 * Whether to have a drop shadow on watermark
370 *
371 * @var bool
372 */
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200373 protected $wm_use_drop_shadow = FALSE;
Andrey Andreev56454792012-05-17 14:32:19 +0300374
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400375 /**
376 * Whether to use truetype fonts
377 *
378 * @var bool
379 */
Andrey Andreev3a459572011-12-21 11:23:11 +0200380 public $wm_use_truetype = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000381
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400382 /**
383 * Initialize Image Library
384 *
385 * @param array $props
Andrey Andreev56454792012-05-17 14:32:19 +0300386 * @return void
Timothy Warrenb82bc3a2012-04-27 09:12:58 -0400387 */
Greg Akera9263282010-11-10 15:26:43 -0600388 public function __construct($props = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 {
390 if (count($props) > 0)
391 {
392 $this->initialize($props);
393 }
394
Andrey Andreev90726b82015-01-20 12:39:22 +0200395 log_message('info', 'Image Lib Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 }
397
398 // --------------------------------------------------------------------
399
400 /**
401 * Initialize image properties
402 *
403 * Resets values in case this class is used in a loop
404 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 * @return void
406 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200407 public function clear()
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 {
Sam Doidge5cb5c0a2013-03-13 01:28:06 +0000409 $props = array('thumb_marker', 'library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path');
Derek Allard2067d1a2008-11-13 22:59:24 +0000410
411 foreach ($props as $val)
412 {
413 $this->$val = '';
414 }
415
Michael Denniscb07a322011-08-20 23:40:59 -0700416 $this->image_library = 'gd2';
417 $this->dynamic_output = FALSE;
Andrey Andreev56454792012-05-17 14:32:19 +0300418 $this->quality = 90;
Michael Denniscb07a322011-08-20 23:40:59 -0700419 $this->create_thumb = FALSE;
420 $this->thumb_marker = '_thumb';
421 $this->maintain_ratio = TRUE;
422 $this->master_dim = 'auto';
423 $this->wm_type = 'text';
424 $this->wm_x_transp = 4;
425 $this->wm_y_transp = 4;
426 $this->wm_font_size = 17;
427 $this->wm_vrt_alignment = 'B';
428 $this->wm_hor_alignment = 'C';
429 $this->wm_padding = 0;
430 $this->wm_hor_offset = 0;
431 $this->wm_vrt_offset = 0;
432 $this->wm_font_color = '#ffffff';
433 $this->wm_shadow_distance = 2;
434 $this->wm_opacity = 50;
435 $this->create_fnc = 'imagecreatetruecolor';
436 $this->copy_fnc = 'imagecopyresampled';
437 $this->error_msg = array();
438 $this->wm_use_drop_shadow = FALSE;
439 $this->wm_use_truetype = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 }
441
442 // --------------------------------------------------------------------
443
444 /**
445 * initialize image preferences
446 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 * @param array
448 * @return bool
449 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200450 public function initialize($props = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 {
Andrey Andreev8e70b792012-01-12 20:19:24 +0200452 // Convert array elements into class variables
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 if (count($props) > 0)
454 {
455 foreach ($props as $key => $val)
456 {
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200457 if (property_exists($this, $key))
458 {
459 if (in_array($key, array('wm_font_color', 'wm_shadow_color')))
460 {
Andrey Andreev8323ae62011-12-31 18:39:10 +0200461 if (preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches))
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200462 {
Andrey Andreevcf2ba9e2012-01-01 21:57:13 +0200463 /* $matches[1] contains our hex color value, but it might be
Andrey Andreev8323ae62011-12-31 18:39:10 +0200464 * both in the full 6-length format or the shortened 3-length
465 * value.
Andrey Andreevbb96c8b2011-12-31 18:48:39 +0200466 * We'll later need the full version, so we keep it if it's
Andrey Andreev8323ae62011-12-31 18:39:10 +0200467 * already there and if not - we'll convert to it. We can
468 * access string characters by their index as in an array,
469 * so we'll do that and use concatenation to form the final
470 * value:
471 */
Andrey Andreev665af0c2011-12-30 14:39:29 +0200472 $val = (strlen($matches[1]) === 6)
473 ? '#'.$matches[1]
474 : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2];
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200475 }
476 else
477 {
478 continue;
479 }
480 }
481
482 $this->$key = $val;
483 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 }
485 }
486
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200487 // Is there a source image? If not, there's no reason to continue
Alex Bilbied261b1e2012-06-02 11:12:16 +0100488 if ($this->source_image === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 {
490 $this->set_error('imglib_source_image_required');
Eric Barnesb1673362011-12-05 22:05:38 -0500491 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 }
493
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200494 /* Is getimagesize() available?
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 *
496 * We use it to determine the image properties (width/height).
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200497 * Note: We need to figure out how to determine image
Derek Allard2067d1a2008-11-13 22:59:24 +0000498 * properties using ImageMagick and NetPBM
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 */
500 if ( ! function_exists('getimagesize'))
501 {
502 $this->set_error('imglib_gd_required_for_props');
503 return FALSE;
504 }
505
506 $this->image_library = strtolower($this->image_library);
507
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200508 /* Set the full server path
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 *
510 * The source image may or may not contain a path.
511 * Either way, we'll try use realpath to generate the
512 * full server path in order to more reliably read it.
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 */
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200514 if (($full_source_path = realpath($this->source_image)) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200516 $full_source_path = str_replace('\\', '/', $full_source_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 }
518 else
519 {
520 $full_source_path = $this->source_image;
521 }
522
523 $x = explode('/', $full_source_path);
524 $this->source_image = end($x);
525 $this->source_folder = str_replace($this->source_image, '', $full_source_path);
526
527 // Set the Image Properties
528 if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
529 {
Eric Barnesb1673362011-12-05 22:05:38 -0500530 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 }
532
533 /*
534 * Assign the "new" image name/path
535 *
536 * If the user has set a "new_image" name it means
537 * we are making a copy of the source image. If not
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200538 * it means we are altering the original. We'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 * set the destination filename and path accordingly.
Derek Allard2067d1a2008-11-13 22:59:24 +0000540 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100541 if ($this->new_image === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 {
543 $this->dest_image = $this->source_image;
544 $this->dest_folder = $this->source_folder;
545 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200546 elseif (strpos($this->new_image, '/') === FALSE)
547 {
548 $this->dest_folder = $this->source_folder;
549 $this->dest_image = $this->new_image;
550 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 else
552 {
Andrey Andreev1b815532012-04-03 16:06:03 +0300553 if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200555 $full_dest_path = str_replace('\\', '/', realpath($this->new_image));
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 }
557 else
558 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200559 $full_dest_path = $this->new_image;
560 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000561
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200562 // Is there a file name?
563 if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path))
564 {
565 $this->dest_folder = $full_dest_path.'/';
566 $this->dest_image = $this->source_image;
567 }
568 else
569 {
570 $x = explode('/', $full_dest_path);
571 $this->dest_image = end($x);
572 $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 }
574 }
575
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200576 /* Compile the finalized filenames/paths
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 *
578 * We'll create two master strings containing the
579 * full server path to the source image and the
580 * full server path to the destination image.
581 * We'll also split the destination image name
582 * so we can insert the thumbnail marker if needed.
Derek Allard2067d1a2008-11-13 22:59:24 +0000583 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100584 if ($this->create_thumb === FALSE OR $this->thumb_marker === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 {
586 $this->thumb_marker = '';
587 }
588
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200589 $xp = $this->explode_name($this->dest_image);
Derek Allard2067d1a2008-11-13 22:59:24 +0000590
591 $filename = $xp['name'];
592 $file_ext = $xp['ext'];
593
594 $this->full_src_path = $this->source_folder.$this->source_image;
595 $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;
596
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200597 /* Should we maintain image proportions?
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 *
599 * When creating thumbs or copies, the target width/height
600 * might not be in correct proportion with the source
Andrey Andreev8e70b792012-01-12 20:19:24 +0200601 * image's width/height. We'll recalculate it here.
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100603 if ($this->maintain_ratio === TRUE && ($this->width !== 0 OR $this->height !== 0))
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 {
605 $this->image_reproportion();
606 }
607
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200608 /* Was a width and height specified?
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 *
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200610 * If the destination width/height was not submitted we
611 * will use the values from the actual file
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100613 if ($this->width === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +0200614 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000615 $this->width = $this->orig_width;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200616 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000617
Alex Bilbied261b1e2012-06-02 11:12:16 +0100618 if ($this->height === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +0200619 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000620 $this->height = $this->orig_height;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200621 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000622
623 // Set the quality
Andrey Andreev8e70b792012-01-12 20:19:24 +0200624 $this->quality = trim(str_replace('%', '', $this->quality));
Derek Allard2067d1a2008-11-13 22:59:24 +0000625
Andrey Andreev7a7ad782012-11-12 17:21:01 +0200626 if ($this->quality === '' OR $this->quality === 0 OR ! ctype_digit($this->quality))
Andrey Andreev8e70b792012-01-12 20:19:24 +0200627 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000628 $this->quality = 90;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200629 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000630
631 // Set the x/y coordinates
Andrey Andreev5036c9c2012-06-04 15:34:56 +0300632 is_numeric($this->x_axis) OR $this->x_axis = 0;
633 is_numeric($this->y_axis) OR $this->y_axis = 0;
Derek Allard2067d1a2008-11-13 22:59:24 +0000634
635 // Watermark-related Stuff...
Alex Bilbied261b1e2012-06-02 11:12:16 +0100636 if ($this->wm_overlay_path !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000637 {
Andrey Andreev8e70b792012-01-12 20:19:24 +0200638 $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path));
Derek Allard2067d1a2008-11-13 22:59:24 +0000639 }
640
Alex Bilbied261b1e2012-06-02 11:12:16 +0100641 if ($this->wm_shadow_color !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 {
643 $this->wm_use_drop_shadow = TRUE;
644 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100645 elseif ($this->wm_use_drop_shadow === TRUE && $this->wm_shadow_color === '')
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200646 {
647 $this->wm_use_drop_shadow = FALSE;
648 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000649
Alex Bilbied261b1e2012-06-02 11:12:16 +0100650 if ($this->wm_font_path !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 {
652 $this->wm_use_truetype = TRUE;
653 }
654
655 return TRUE;
656 }
657
658 // --------------------------------------------------------------------
659
660 /**
661 * Image Resize
662 *
663 * This is a wrapper function that chooses the proper
664 * resize function based on the protocol specified
665 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000666 * @return bool
667 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200668 public function resize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 {
Andrey Andreev1a9f52c2012-01-07 01:06:34 +0200670 $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000671 return $this->$protocol('resize');
672 }
673
674 // --------------------------------------------------------------------
675
676 /**
677 * Image Crop
678 *
679 * This is a wrapper function that chooses the proper
680 * cropping function based on the protocol specified
681 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000682 * @return bool
683 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200684 public function crop()
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 {
Andrey Andreev5a67e3d2012-01-07 01:21:09 +0200686 $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000687 return $this->$protocol('crop');
688 }
689
690 // --------------------------------------------------------------------
691
692 /**
693 * Image Rotate
694 *
695 * This is a wrapper function that chooses the proper
696 * rotation function based on the protocol specified
697 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000698 * @return bool
699 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200700 public function rotate()
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 {
702 // Allowed rotation values
703 $degs = array(90, 180, 270, 'vrt', 'hor');
704
Alex Bilbied261b1e2012-06-02 11:12:16 +0100705 if ($this->rotation_angle === '' OR ! in_array($this->rotation_angle, $degs))
Derek Allard2067d1a2008-11-13 22:59:24 +0000706 {
707 $this->set_error('imglib_rotation_angle_required');
Eric Barnesb1673362011-12-05 22:05:38 -0500708 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000709 }
710
711 // Reassign the width and height
Alex Bilbied261b1e2012-06-02 11:12:16 +0100712 if ($this->rotation_angle === 90 OR $this->rotation_angle === 270)
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 {
714 $this->width = $this->orig_height;
715 $this->height = $this->orig_width;
716 }
717 else
718 {
719 $this->width = $this->orig_width;
720 $this->height = $this->orig_height;
721 }
722
Derek Allard2067d1a2008-11-13 22:59:24 +0000723 // Choose resizing function
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200724 if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm')
Derek Allard2067d1a2008-11-13 22:59:24 +0000725 {
726 $protocol = 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000727 return $this->$protocol('rotate');
728 }
729
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200730 return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
731 ? $this->image_mirror_gd()
732 : $this->image_rotate_gd();
Derek Allard2067d1a2008-11-13 22:59:24 +0000733 }
734
735 // --------------------------------------------------------------------
736
737 /**
738 * Image Process Using GD/GD2
739 *
740 * This function will resize or crop
741 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000742 * @param string
743 * @return bool
744 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200745 public function image_process_gd($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 {
747 $v2_override = FALSE;
748
749 // If the target width/height match the source, AND if the new file name is not equal to the old file name
750 // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
Alex Bilbied261b1e2012-06-02 11:12:16 +0100751 if ($this->dynamic_output === FALSE && $this->orig_width === $this->width && $this->orig_height === $this->height)
Derek Allard2067d1a2008-11-13 22:59:24 +0000752 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100753 if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000754 {
Andrey Andreev45965742014-08-27 20:40:11 +0300755 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000756 }
Andrey Andreeva92b9032011-12-24 19:05:58 +0200757
758 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 }
760
761 // Let's set up our values based on the action
Alex Bilbied261b1e2012-06-02 11:12:16 +0100762 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000763 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200764 // Reassign the source width/height if cropping
Derek Jones4b9c6292011-07-01 17:40:48 -0500765 $this->orig_width = $this->width;
Derek Allard2067d1a2008-11-13 22:59:24 +0000766 $this->orig_height = $this->height;
767
768 // GD 2.0 has a cropping bug so we'll test for it
769 if ($this->gd_version() !== FALSE)
770 {
771 $gd_version = str_replace('0', '', $this->gd_version());
Andrey Andreevd4818b72014-10-23 17:15:32 +0300772 $v2_override = ($gd_version == 2);
Derek Allard2067d1a2008-11-13 22:59:24 +0000773 }
774 }
775 else
776 {
777 // If resizing the x/y axis must be zero
778 $this->x_axis = 0;
779 $this->y_axis = 0;
780 }
781
Andrey Andreev10fb7d12015-08-03 10:05:29 +0300782 // Create the image handle
Derek Allard2067d1a2008-11-13 22:59:24 +0000783 if ( ! ($src_img = $this->image_create_gd()))
784 {
785 return FALSE;
786 }
787
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200788 /* Create the image
789 *
790 * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
791 * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
792 * below should that ever prove inaccurate.
793 *
Alex Bilbied261b1e2012-06-02 11:12:16 +0100794 * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override === FALSE)
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200795 */
Andrey Andreev8e70b792012-01-12 20:19:24 +0200796 if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000797 {
798 $create = 'imagecreatetruecolor';
799 $copy = 'imagecopyresampled';
800 }
801 else
802 {
803 $create = 'imagecreate';
804 $copy = 'imagecopyresized';
805 }
806
807 $dst_img = $create($this->width, $this->height);
Derek Jones595bfd12010-08-20 10:28:22 -0500808
Alex Bilbied261b1e2012-06-02 11:12:16 +0100809 if ($this->image_type === 3) // png we can actually preserve transparency
Derek Jones595bfd12010-08-20 10:28:22 -0500810 {
811 imagealphablending($dst_img, FALSE);
812 imagesavealpha($dst_img, TRUE);
813 }
Barry Mienydd671972010-10-04 16:33:58 +0200814
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
816
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200817 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +0100818 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 {
820 $this->image_display_gd($dst_img);
821 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200822 elseif ( ! $this->image_save_gd($dst_img)) // Or save it
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200824 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 }
826
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200827 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +0000828 imagedestroy($dst_img);
829 imagedestroy($src_img);
830
Andrey Andreev45965742014-08-27 20:40:11 +0300831 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000832
833 return TRUE;
834 }
835
836 // --------------------------------------------------------------------
837
838 /**
839 * Image Process Using ImageMagick
840 *
841 * This function will resize, crop or rotate
842 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000843 * @param string
844 * @return bool
845 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200846 public function image_process_imagemagick($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000847 {
Andrey Andreev3a197592015-05-21 01:05:06 +0300848 // Do we have a vaild library path?
Alex Bilbied261b1e2012-06-02 11:12:16 +0100849 if ($this->library_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000850 {
851 $this->set_error('imglib_libpath_invalid');
852 return FALSE;
853 }
854
Andrey Andreev8e70b792012-01-12 20:19:24 +0200855 if ( ! preg_match('/convert$/i', $this->library_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000856 {
Andrey Andreeva92b9032011-12-24 19:05:58 +0200857 $this->library_path = rtrim($this->library_path, '/').'/convert';
Derek Allard2067d1a2008-11-13 22:59:24 +0000858 }
859
860 // Execute the command
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200861 $cmd = $this->library_path.' -quality '.$this->quality;
Derek Allard2067d1a2008-11-13 22:59:24 +0000862
Alex Bilbied261b1e2012-06-02 11:12:16 +0100863 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 {
Andrey Andreev8e70b792012-01-12 20:19:24 +0200865 $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1';
Derek Allard2067d1a2008-11-13 22:59:24 +0000866 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100867 elseif ($action === 'rotate')
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200869 $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
870 ? '-flop' : '-rotate '.$this->rotation_angle;
Derek Allard2067d1a2008-11-13 22:59:24 +0000871
Andrey Andreev8e70b792012-01-12 20:19:24 +0200872 $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 }
Andrey Andreev8e70b792012-01-12 20:19:24 +0200874 else // Resize
Derek Allard2067d1a2008-11-13 22:59:24 +0000875 {
Omar24063af2012-07-02 13:50:17 -0300876 if($this->maintain_ratio === TRUE)
877 {
878 $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
879 }
Omarbb531d62012-06-29 10:48:28 -0300880 else
Omar24063af2012-07-02 13:50:17 -0300881 {
882 $cmd .= ' -resize '.$this->width.'x'.$this->height.'\! "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
883 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000884 }
885
886 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200887 // exec() might be disabled
888 if (function_usable('exec'))
889 {
890 @exec($cmd, $output, $retval);
891 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000892
Andrey Andreev8e70b792012-01-12 20:19:24 +0200893 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 if ($retval > 0)
895 {
896 $this->set_error('imglib_image_process_failed');
897 return FALSE;
898 }
899
Andrey Andreev45965742014-08-27 20:40:11 +0300900 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000901
902 return TRUE;
903 }
904
905 // --------------------------------------------------------------------
906
907 /**
908 * Image Process Using NetPBM
909 *
910 * This function will resize, crop or rotate
911 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000912 * @param string
913 * @return bool
914 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200915 public function image_process_netpbm($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100917 if ($this->library_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000918 {
919 $this->set_error('imglib_libpath_invalid');
920 return FALSE;
921 }
922
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200923 // Build the resizing command
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 switch ($this->image_type)
925 {
926 case 1 :
Andrey Andreev56454792012-05-17 14:32:19 +0300927 $cmd_in = 'giftopnm';
928 $cmd_out = 'ppmtogif';
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 break;
930 case 2 :
Andrey Andreev56454792012-05-17 14:32:19 +0300931 $cmd_in = 'jpegtopnm';
932 $cmd_out = 'ppmtojpeg';
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 break;
934 case 3 :
Andrey Andreev56454792012-05-17 14:32:19 +0300935 $cmd_in = 'pngtopnm';
936 $cmd_out = 'ppmtopng';
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 break;
938 }
939
Alex Bilbied261b1e2012-06-02 11:12:16 +0100940 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000941 {
942 $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
943 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100944 elseif ($action === 'rotate')
Derek Allard2067d1a2008-11-13 22:59:24 +0000945 {
946 switch ($this->rotation_angle)
947 {
Andrey Andreev56454792012-05-17 14:32:19 +0300948 case 90: $angle = 'r270';
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300950 case 180: $angle = 'r180';
Derek Allard2067d1a2008-11-13 22:59:24 +0000951 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300952 case 270: $angle = 'r90';
Derek Allard2067d1a2008-11-13 22:59:24 +0000953 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300954 case 'vrt': $angle = 'tb';
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300956 case 'hor': $angle = 'lr';
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 break;
958 }
959
960 $cmd_inner = 'pnmflip -'.$angle.' ';
961 }
962 else // Resize
963 {
964 $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
965 }
966
967 $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
968
969 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200970 // exec() might be disabled
971 if (function_usable('exec'))
972 {
973 @exec($cmd, $output, $retval);
974 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000975
Andrey Andreev8e70b792012-01-12 20:19:24 +0200976 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 if ($retval > 0)
978 {
979 $this->set_error('imglib_image_process_failed');
980 return FALSE;
981 }
982
983 // With NetPBM we have to create a temporary image.
984 // If you try manipulating the original it fails so
985 // we have to rename the temp file.
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200986 copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200987 unlink($this->dest_folder.'netpbm.tmp');
Andrey Andreev45965742014-08-27 20:40:11 +0300988 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000989
990 return TRUE;
991 }
992
993 // --------------------------------------------------------------------
994
995 /**
996 * Image Rotate Using GD
997 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000998 * @return bool
999 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001000 public function image_rotate_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001001 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001002 // Create the image handle
Derek Allard2067d1a2008-11-13 22:59:24 +00001003 if ( ! ($src_img = $this->image_create_gd()))
1004 {
1005 return FALSE;
1006 }
1007
1008 // Set the background color
1009 // This won't work with transparent PNG files so we are
1010 // going to have to figure out how to determine the color
1011 // of the alpha channel in a future release.
1012
Andrey Andreev3a197592015-05-21 01:05:06 +03001013 $white = imagecolorallocate($src_img, 255, 255, 255);
Derek Allard2067d1a2008-11-13 22:59:24 +00001014
Andrey Andreev8e70b792012-01-12 20:19:24 +02001015 // Rotate it!
Derek Allard2067d1a2008-11-13 22:59:24 +00001016 $dst_img = imagerotate($src_img, $this->rotation_angle, $white);
1017
Andrey Andreev8e70b792012-01-12 20:19:24 +02001018 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001019 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001020 {
1021 $this->image_display_gd($dst_img);
1022 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001023 elseif ( ! $this->image_save_gd($dst_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001024 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001025 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001026 }
1027
Andrey Andreev8e70b792012-01-12 20:19:24 +02001028 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 imagedestroy($dst_img);
1030 imagedestroy($src_img);
1031
Andrey Andreev45965742014-08-27 20:40:11 +03001032 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001033
Pascal Kriete8761ef52011-02-14 13:13:52 -05001034 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001035 }
1036
1037 // --------------------------------------------------------------------
1038
1039 /**
1040 * Create Mirror Image using GD
1041 *
1042 * This function will flip horizontal or vertical
1043 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001044 * @return bool
1045 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001046 public function image_mirror_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001047 {
1048 if ( ! $src_img = $this->image_create_gd())
1049 {
1050 return FALSE;
1051 }
1052
Derek Jones4b9c6292011-07-01 17:40:48 -05001053 $width = $this->orig_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001054 $height = $this->orig_height;
1055
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001056 if ($this->rotation_angle === 'hor')
Derek Allard2067d1a2008-11-13 22:59:24 +00001057 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001058 for ($i = 0; $i < $height; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001059 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001060 $left = 0;
1061 $right = $width - 1;
1062
Derek Allard2067d1a2008-11-13 22:59:24 +00001063 while ($left < $right)
1064 {
1065 $cl = imagecolorat($src_img, $left, $i);
1066 $cr = imagecolorat($src_img, $right, $i);
1067
1068 imagesetpixel($src_img, $left, $i, $cr);
1069 imagesetpixel($src_img, $right, $i, $cl);
1070
1071 $left++;
1072 $right--;
1073 }
1074 }
1075 }
1076 else
1077 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001078 for ($i = 0; $i < $width; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001079 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001080 $top = 0;
1081 $bottom = $height - 1;
1082
Andrey Andreev5d78fd82015-05-11 18:19:01 +03001083 while ($top < $bottom)
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 {
1085 $ct = imagecolorat($src_img, $i, $top);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001086 $cb = imagecolorat($src_img, $i, $bottom);
Derek Allard2067d1a2008-11-13 22:59:24 +00001087
1088 imagesetpixel($src_img, $i, $top, $cb);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001089 imagesetpixel($src_img, $i, $bottom, $ct);
Derek Allard2067d1a2008-11-13 22:59:24 +00001090
1091 $top++;
Andrey Andreevfbde2792015-05-11 11:03:06 +03001092 $bottom--;
Derek Allard2067d1a2008-11-13 22:59:24 +00001093 }
1094 }
1095 }
1096
Andrey Andreev8e70b792012-01-12 20:19:24 +02001097 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001098 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001099 {
1100 $this->image_display_gd($src_img);
1101 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001102 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001104 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001105 }
1106
Andrey Andreev8e70b792012-01-12 20:19:24 +02001107 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001108 imagedestroy($src_img);
1109
Andrey Andreev45965742014-08-27 20:40:11 +03001110 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001111
1112 return TRUE;
1113 }
1114
1115 // --------------------------------------------------------------------
1116
1117 /**
1118 * Image Watermark
1119 *
1120 * This is a wrapper function that chooses the type
1121 * of watermarking based on the specified preference.
1122 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001123 * @return bool
1124 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001125 public function watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001126 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001127 return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
Derek Allard2067d1a2008-11-13 22:59:24 +00001128 }
1129
1130 // --------------------------------------------------------------------
1131
1132 /**
1133 * Watermark - Graphic Version
1134 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001135 * @return bool
1136 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001137 public function overlay_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001138 {
1139 if ( ! function_exists('imagecolortransparent'))
1140 {
1141 $this->set_error('imglib_gd_required');
1142 return FALSE;
1143 }
1144
Andrey Andreev8e70b792012-01-12 20:19:24 +02001145 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001146 $this->get_image_properties();
1147
Andrey Andreev8e70b792012-01-12 20:19:24 +02001148 // Fetch watermark image properties
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001149 $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001150 $wm_img_type = $props['image_type'];
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001151 $wm_width = $props['width'];
1152 $wm_height = $props['height'];
Derek Allard2067d1a2008-11-13 22:59:24 +00001153
Andrey Andreev8e70b792012-01-12 20:19:24 +02001154 // Create two image resources
Derek Jones4b9c6292011-07-01 17:40:48 -05001155 $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001156 $src_img = $this->image_create_gd($this->full_src_path);
1157
1158 // Reverse the offset if necessary
1159 // When the image is positioned at the bottom
1160 // we don't want the vertical offset to push it
Andrey Andreev8e70b792012-01-12 20:19:24 +02001161 // further down. We want the reverse, so we'll
1162 // invert the offset. Same with the horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001163 // offset when the image is at the right
1164
Andrey Andreev8e70b792012-01-12 20:19:24 +02001165 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1166 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001167
Alex Bilbied261b1e2012-06-02 11:12:16 +01001168 if ($this->wm_vrt_alignment === 'B')
Derek Allard2067d1a2008-11-13 22:59:24 +00001169 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
1170
Alex Bilbied261b1e2012-06-02 11:12:16 +01001171 if ($this->wm_hor_alignment === 'R')
Derek Allard2067d1a2008-11-13 22:59:24 +00001172 $this->wm_hor_offset = $this->wm_hor_offset * -1;
1173
Andrey Andreev8e70b792012-01-12 20:19:24 +02001174 // Set the base x and y axis values
Derek Allard2067d1a2008-11-13 22:59:24 +00001175 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1176 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1177
Andrey Andreev8e70b792012-01-12 20:19:24 +02001178 // Set the vertical position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001179 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001180 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001181 $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
1182 }
1183 elseif ($this->wm_vrt_alignment === 'B')
1184 {
1185 $y_axis += $this->orig_height - $wm_height;
Derek Allard2067d1a2008-11-13 22:59:24 +00001186 }
1187
Andrey Andreev8e70b792012-01-12 20:19:24 +02001188 // Set the horizontal position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001189 if ($this->wm_hor_alignment === 'C')
Derek Allard2067d1a2008-11-13 22:59:24 +00001190 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001191 $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
1192 }
1193 elseif ($this->wm_hor_alignment === 'R')
1194 {
1195 $x_axis += $this->orig_width - $wm_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001196 }
1197
Andrey Andreev10fb7d12015-08-03 10:05:29 +03001198 // Build the finalized image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001199 if ($wm_img_type === 3 && function_exists('imagealphablending'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001200 {
1201 @imagealphablending($src_img, TRUE);
Barry Mienydd671972010-10-04 16:33:58 +02001202 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001203
1204 // Set RGB values for text and shadow
1205 $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
1206 $alpha = ($rgba & 0x7F000000) >> 24;
1207
1208 // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency
1209 if ($alpha > 0)
1210 {
1211 // copy the image directly, the image's alpha transparency being the sole determinant of blending
1212 imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
1213 }
1214 else
1215 {
1216 // set our RGB value from above to be transparent and merge the images with the specified opacity
1217 imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp));
1218 imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
1219 }
1220
Andrey Andreevdb037db2015-01-12 13:45:12 +02001221 // We can preserve transparency for PNG images
Дмитрийb23b8fc2014-10-20 00:36:55 +04001222 if ($this->image_type === 3)
1223 {
1224 imagealphablending($src_img, FALSE);
1225 imagesavealpha($src_img, TRUE);
1226 }
1227
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001228 // Output the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001229 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001230 {
1231 $this->image_display_gd($src_img);
1232 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001233 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001234 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001235 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001236 }
1237
1238 imagedestroy($src_img);
1239 imagedestroy($wm_img);
1240
1241 return TRUE;
1242 }
1243
1244 // --------------------------------------------------------------------
1245
1246 /**
1247 * Watermark - Text Version
1248 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001249 * @return bool
1250 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001251 public function text_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001252 {
1253 if ( ! ($src_img = $this->image_create_gd()))
1254 {
1255 return FALSE;
1256 }
1257
Alex Bilbied261b1e2012-06-02 11:12:16 +01001258 if ($this->wm_use_truetype === TRUE && ! file_exists($this->wm_font_path))
Derek Allard2067d1a2008-11-13 22:59:24 +00001259 {
1260 $this->set_error('imglib_missing_font');
1261 return FALSE;
1262 }
1263
Andrey Andreev8e70b792012-01-12 20:19:24 +02001264 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001265 $this->get_image_properties();
1266
Derek Allard2067d1a2008-11-13 22:59:24 +00001267 // Reverse the vertical offset
1268 // When the image is positioned at the bottom
1269 // we don't want the vertical offset to push it
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001270 // further down. We want the reverse, so we'll
Andrey Andreev8e70b792012-01-12 20:19:24 +02001271 // invert the offset. Note: The horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001272 // offset flips itself automatically
1273
Alex Bilbied261b1e2012-06-02 11:12:16 +01001274 if ($this->wm_vrt_alignment === 'B')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001275 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001277 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001278
Alex Bilbied261b1e2012-06-02 11:12:16 +01001279 if ($this->wm_hor_alignment === 'R')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001280 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001281 $this->wm_hor_offset = $this->wm_hor_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001282 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001283
1284 // Set font width and height
1285 // These are calculated differently depending on
1286 // whether we are using the true type font or not
Alex Bilbied261b1e2012-06-02 11:12:16 +01001287 if ($this->wm_use_truetype === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001288 {
Andrey Andreeve52fc262014-02-11 13:27:01 +02001289 if (empty($this->wm_font_size))
Andrey Andreeva92b9032011-12-24 19:05:58 +02001290 {
1291 $this->wm_font_size = 17;
1292 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001293
Andrey Andreeve52fc262014-02-11 13:27:01 +02001294 if (function_exists('imagettfbbox'))
1295 {
1296 $temp = imagettfbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text);
1297 $temp = $temp[2] - $temp[0];
1298
1299 $fontwidth = $temp / strlen($this->wm_text);
1300 }
1301 else
1302 {
1303 $fontwidth = $this->wm_font_size - ($this->wm_font_size / 4);
1304 }
1305
Derek Allard2067d1a2008-11-13 22:59:24 +00001306 $fontheight = $this->wm_font_size;
1307 $this->wm_vrt_offset += $this->wm_font_size;
1308 }
1309 else
1310 {
Derek Jones4b9c6292011-07-01 17:40:48 -05001311 $fontwidth = imagefontwidth($this->wm_font_size);
Derek Allard2067d1a2008-11-13 22:59:24 +00001312 $fontheight = imagefontheight($this->wm_font_size);
1313 }
1314
1315 // Set base X and Y axis values
1316 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1317 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1318
Alex Bilbied261b1e2012-06-02 11:12:16 +01001319 if ($this->wm_use_drop_shadow === FALSE)
omar0779e992015-01-31 11:57:07 -07001320 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001321 $this->wm_shadow_distance = 0;
omar0779e992015-01-31 11:57:07 -07001322 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001323
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001324 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1325 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001326
omar0779e992015-01-31 11:57:07 -07001327 // Set vertical alignment
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001328 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001329 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001330 $y_axis += ($this->orig_height / 2) + ($fontheight / 2);
1331 }
1332 elseif ($this->wm_vrt_alignment === 'B')
1333 {
1334 $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2);
Derek Allard2067d1a2008-11-13 22:59:24 +00001335 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001336
omar0779e992015-01-31 11:57:07 -07001337 // Set horizontal alignment
1338 if ($this->wm_hor_alignment === 'R')
1339 {
omar9c855322015-01-31 11:58:03 -07001340 $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)) - $this->wm_shadow_distance;
omar0779e992015-01-31 11:57:07 -07001341 }
1342 elseif ($this->wm_hor_alignment === 'C')
1343 {
1344 $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
1345 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001346
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001347 if ($this->wm_use_drop_shadow)
Derek Allard2067d1a2008-11-13 22:59:24 +00001348 {
omar0779e992015-01-31 11:57:07 -07001349 // Offset from text
1350 $x_shad = $x_axis + $this->wm_shadow_distance;
1351 $y_shad = $y_axis + $this->wm_shadow_distance;
Andrey Andreev3a197592015-05-21 01:05:06 +03001352
omar0779e992015-01-31 11:57:07 -07001353 /* Set RGB values for shadow
Andrey Andreev8323ae62011-12-31 18:39:10 +02001354 *
1355 * First character is #, so we don't really need it.
1356 * Get the rest of the string and split it into 2-length
1357 * hex values:
1358 */
Andrey Andreev8323ae62011-12-31 18:39:10 +02001359 $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2);
Ronald Beilsma8f80bc42012-01-12 16:41:49 +01001360 $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2]));
Andrey Andreev3a197592015-05-21 01:05:06 +03001361
omar0779e992015-01-31 11:57:07 -07001362 // Add the shadow to the source image
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001363 if ($this->wm_use_truetype)
1364 {
1365 imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001366 }
1367 else
1368 {
1369 imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001370 }
omar0779e992015-01-31 11:57:07 -07001371 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001372
omar0779e992015-01-31 11:57:07 -07001373 /* Set RGB values for text
1374 *
1375 * First character is #, so we don't really need it.
1376 * Get the rest of the string and split it into 2-length
1377 * hex values:
1378 */
1379 $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2);
1380 $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2]));
Andrey Andreev99ae2262012-10-05 15:14:30 +03001381
omar0779e992015-01-31 11:57:07 -07001382 // Add the text to the source image
1383 if ($this->wm_use_truetype)
1384 {
1385 imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text);
1386 }
1387 else
1388 {
1389 imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
1390 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001391
omar0779e992015-01-31 11:57:07 -07001392 // We can preserve transparency for PNG images
1393 if ($this->image_type === 3)
1394 {
1395 imagealphablending($src_img, FALSE);
1396 imagesavealpha($src_img, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001397 }
1398
Andrey Andreev8e70b792012-01-12 20:19:24 +02001399 // Output the final image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001400 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001401 {
1402 $this->image_display_gd($src_img);
1403 }
1404 else
1405 {
1406 $this->image_save_gd($src_img);
1407 }
1408
1409 imagedestroy($src_img);
1410
1411 return TRUE;
1412 }
1413
1414 // --------------------------------------------------------------------
1415
1416 /**
1417 * Create Image - GD
1418 *
1419 * This simply creates an image resource handle
1420 * based on the type of image being processed
1421 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001422 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001423 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001424 * @return resource
1425 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001426 public function image_create_gd($path = '', $image_type = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001427 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001428 if ($path === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001429 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001430 $path = $this->full_src_path;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001431 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001432
Alex Bilbied261b1e2012-06-02 11:12:16 +01001433 if ($image_type === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001434 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001435 $image_type = $this->image_type;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001436 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001437
Derek Allard2067d1a2008-11-13 22:59:24 +00001438 switch ($image_type)
1439 {
Andrey Andreev3a197592015-05-21 01:05:06 +03001440 case 1:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001441 if ( ! function_exists('imagecreatefromgif'))
1442 {
1443 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1444 return FALSE;
1445 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001446
Andrey Andreeve52fc262014-02-11 13:27:01 +02001447 return imagecreatefromgif($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001448 case 2:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001449 if ( ! function_exists('imagecreatefromjpeg'))
1450 {
1451 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1452 return FALSE;
1453 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001454
Andrey Andreeve52fc262014-02-11 13:27:01 +02001455 return imagecreatefromjpeg($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001456 case 3:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001457 if ( ! function_exists('imagecreatefrompng'))
1458 {
1459 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1460 return FALSE;
1461 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001462
Andrey Andreeve52fc262014-02-11 13:27:01 +02001463 return imagecreatefrompng($path);
1464 default:
1465 $this->set_error(array('imglib_unsupported_imagecreate'));
1466 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001467 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001468 }
1469
1470 // --------------------------------------------------------------------
1471
1472 /**
1473 * Write image file to disk - GD
1474 *
1475 * Takes an image resource as input and writes the file
1476 * to the specified destination
1477 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001478 * @param resource
1479 * @return bool
1480 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001481 public function image_save_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001482 {
1483 switch ($this->image_type)
1484 {
Andrey Andreev56454792012-05-17 14:32:19 +03001485 case 1:
1486 if ( ! function_exists('imagegif'))
1487 {
1488 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1489 return FALSE;
1490 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001491
Andrey Andreev56454792012-05-17 14:32:19 +03001492 if ( ! @imagegif($resource, $this->full_dst_path))
1493 {
1494 $this->set_error('imglib_save_failed');
1495 return FALSE;
1496 }
1497 break;
1498 case 2:
1499 if ( ! function_exists('imagejpeg'))
1500 {
1501 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1502 return FALSE;
1503 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001504
Andrey Andreev56454792012-05-17 14:32:19 +03001505 if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
1506 {
1507 $this->set_error('imglib_save_failed');
1508 return FALSE;
1509 }
1510 break;
1511 case 3:
1512 if ( ! function_exists('imagepng'))
1513 {
1514 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1515 return FALSE;
1516 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001517
Andrey Andreev56454792012-05-17 14:32:19 +03001518 if ( ! @imagepng($resource, $this->full_dst_path))
1519 {
1520 $this->set_error('imglib_save_failed');
1521 return FALSE;
1522 }
1523 break;
1524 default:
1525 $this->set_error(array('imglib_unsupported_imagecreate'));
1526 return FALSE;
1527 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001528 }
1529
1530 return TRUE;
1531 }
1532
1533 // --------------------------------------------------------------------
1534
1535 /**
1536 * Dynamically outputs an image
1537 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001538 * @param resource
1539 * @return void
1540 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001541 public function image_display_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001542 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001543 header('Content-Disposition: filename='.$this->source_image.';');
1544 header('Content-Type: '.$this->mime_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001545 header('Content-Transfer-Encoding: binary');
1546 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
1547
1548 switch ($this->image_type)
1549 {
Andrey Andreev56454792012-05-17 14:32:19 +03001550 case 1 : imagegif($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001551 break;
Ted Wood9cc707b2013-01-08 19:41:45 -08001552 case 2 : imagejpeg($resource, NULL, $this->quality);
Derek Allard2067d1a2008-11-13 22:59:24 +00001553 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001554 case 3 : imagepng($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001555 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001556 default: echo 'Unable to display the image';
Derek Allard2067d1a2008-11-13 22:59:24 +00001557 break;
1558 }
1559 }
1560
1561 // --------------------------------------------------------------------
1562
1563 /**
1564 * Re-proportion Image Width/Height
1565 *
1566 * When creating thumbs, the desired width/height
1567 * can end up warping the image due to an incorrect
1568 * ratio between the full-sized image and the thumb.
1569 *
1570 * This function lets us re-proportion the width/height
1571 * if users choose to maintain the aspect ratio when resizing.
1572 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001573 * @return void
1574 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001575 public function image_reproportion()
Derek Allard2067d1a2008-11-13 22:59:24 +00001576 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001577 if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001578 OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
1579 OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
Derek Allard2067d1a2008-11-13 22:59:24 +00001580 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001581 return;
Derek Allard2067d1a2008-11-13 22:59:24 +00001582 }
1583
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001584 // Sanitize
Andrey Andreev8e70b792012-01-12 20:19:24 +02001585 $this->width = (int) $this->width;
1586 $this->height = (int) $this->height;
1587
1588 if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
Derek Allard2067d1a2008-11-13 22:59:24 +00001589 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001590 if ($this->width > 0 && $this->height > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001591 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001592 $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
1593 ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001594 }
1595 else
1596 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001597 $this->master_dim = ($this->height === 0) ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001598 }
1599 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001600 elseif (($this->master_dim === 'width' && $this->width === 0)
1601 OR ($this->master_dim === 'height' && $this->height === 0))
1602 {
1603 return;
1604 }
1605
1606 if ($this->master_dim === 'width')
1607 {
1608 $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
1609 }
1610 else
1611 {
1612 $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
1613 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001614 }
1615
1616 // --------------------------------------------------------------------
1617
1618 /**
1619 * Get image properties
1620 *
1621 * A helper function that gets info about the file
1622 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001623 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001624 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001625 * @return mixed
1626 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001627 public function get_image_properties($path = '', $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001628 {
1629 // For now we require GD but we should
1630 // find a way to determine this using IM or NetPBM
1631
Alex Bilbied261b1e2012-06-02 11:12:16 +01001632 if ($path === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +02001633 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001634 $path = $this->full_src_path;
Andrey Andreev8e70b792012-01-12 20:19:24 +02001635 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001636
1637 if ( ! file_exists($path))
1638 {
1639 $this->set_error('imglib_invalid_path');
1640 return FALSE;
1641 }
1642
Phil Sturgeon901998a2011-08-26 10:03:33 +01001643 $vals = getimagesize($path);
Derek Allard2067d1a2008-11-13 22:59:24 +00001644 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
Andrey Andreeva92b9032011-12-24 19:05:58 +02001645 $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001646
Alex Bilbied261b1e2012-06-02 11:12:16 +01001647 if ($return === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001648 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001649 return array(
1650 'width' => $vals[0],
1651 'height' => $vals[1],
1652 'image_type' => $vals[2],
1653 'size_str' => $vals[3],
1654 'mime_type' => $mime
1655 );
Derek Allard2067d1a2008-11-13 22:59:24 +00001656 }
1657
Andrey Andreeva92b9032011-12-24 19:05:58 +02001658 $this->orig_width = $vals[0];
1659 $this->orig_height = $vals[1];
1660 $this->image_type = $vals[2];
1661 $this->size_str = $vals[3];
Derek Allard2067d1a2008-11-13 22:59:24 +00001662 $this->mime_type = $mime;
1663
1664 return TRUE;
1665 }
1666
1667 // --------------------------------------------------------------------
1668
1669 /**
1670 * Size calculator
1671 *
1672 * This function takes a known width x height and
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001673 * recalculates it to a new size. Only one
Derek Allard2067d1a2008-11-13 22:59:24 +00001674 * new variable needs to be known
1675 *
1676 * $props = array(
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001677 * 'width' => $width,
1678 * 'height' => $height,
1679 * 'new_width' => 40,
1680 * 'new_height' => ''
1681 * );
Derek Allard2067d1a2008-11-13 22:59:24 +00001682 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001683 * @param array
1684 * @return array
1685 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001686 public function size_calculator($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001687 {
1688 if ( ! is_array($vals))
1689 {
1690 return;
1691 }
1692
1693 $allowed = array('new_width', 'new_height', 'width', 'height');
1694
1695 foreach ($allowed as $item)
1696 {
Andrey Andreev56454792012-05-17 14:32:19 +03001697 if (empty($vals[$item]))
1698 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001699 $vals[$item] = 0;
Andrey Andreev56454792012-05-17 14:32:19 +03001700 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001701 }
1702
Alex Bilbied261b1e2012-06-02 11:12:16 +01001703 if ($vals['width'] === 0 OR $vals['height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001704 {
1705 return $vals;
1706 }
1707
Alex Bilbied261b1e2012-06-02 11:12:16 +01001708 if ($vals['new_width'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001709 {
1710 $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
1711 }
Alex Bilbied261b1e2012-06-02 11:12:16 +01001712 elseif ($vals['new_height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001713 {
1714 $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
1715 }
1716
1717 return $vals;
1718 }
1719
1720 // --------------------------------------------------------------------
1721
1722 /**
1723 * Explode source_image
1724 *
1725 * This is a helper function that extracts the extension
Derek Jones4b9c6292011-07-01 17:40:48 -05001726 * from the source_image. This function lets us deal with
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001727 * source_images with multiple periods, like: my.cool.jpg
Derek Allard2067d1a2008-11-13 22:59:24 +00001728 * It returns an associative array with two elements:
Derek Jones4b9c6292011-07-01 17:40:48 -05001729 * $array['ext'] = '.jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001730 * $array['name'] = 'my.cool';
1731 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001732 * @param array
1733 * @return array
1734 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001735 public function explode_name($source_image)
Derek Allard2067d1a2008-11-13 22:59:24 +00001736 {
Derek Jones08cae632009-02-10 20:03:29 +00001737 $ext = strrchr($source_image, '.');
1738 $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext));
Barry Mienydd671972010-10-04 16:33:58 +02001739
Derek Jones08cae632009-02-10 20:03:29 +00001740 return array('ext' => $ext, 'name' => $name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001741 }
1742
1743 // --------------------------------------------------------------------
1744
1745 /**
1746 * Is GD Installed?
1747 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001748 * @return bool
1749 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001750 public function gd_loaded()
Derek Allard2067d1a2008-11-13 22:59:24 +00001751 {
1752 if ( ! extension_loaded('gd'))
1753 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001754 /* As it is stated in the PHP manual, dl() is not always available
1755 * and even if so - it could generate an E_WARNING message on failure
1756 */
Andrey Andreev8e70b792012-01-12 20:19:24 +02001757 return (function_exists('dl') && @dl('gd.so'));
Derek Allard2067d1a2008-11-13 22:59:24 +00001758 }
1759
1760 return TRUE;
1761 }
1762
1763 // --------------------------------------------------------------------
1764
1765 /**
1766 * Get GD version
1767 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001768 * @return mixed
1769 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001770 public function gd_version()
Derek Allard2067d1a2008-11-13 22:59:24 +00001771 {
1772 if (function_exists('gd_info'))
1773 {
1774 $gd_version = @gd_info();
Andrey Andreev8e70b792012-01-12 20:19:24 +02001775 return preg_replace('/\D/', '', $gd_version['GD Version']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001776 }
1777
1778 return FALSE;
1779 }
1780
1781 // --------------------------------------------------------------------
1782
1783 /**
1784 * Set error message
1785 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001786 * @param string
1787 * @return void
1788 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001789 public function set_error($msg)
Derek Allard2067d1a2008-11-13 22:59:24 +00001790 {
1791 $CI =& get_instance();
1792 $CI->lang->load('imglib');
1793
1794 if (is_array($msg))
1795 {
1796 foreach ($msg as $val)
1797 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001798 $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001799 $this->error_msg[] = $msg;
1800 log_message('error', $msg);
1801 }
1802 }
1803 else
1804 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001805 $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg);
Derek Allard2067d1a2008-11-13 22:59:24 +00001806 $this->error_msg[] = $msg;
1807 log_message('error', $msg);
1808 }
1809 }
1810
1811 // --------------------------------------------------------------------
1812
1813 /**
1814 * Show error messages
1815 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001816 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001817 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001818 * @return string
1819 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001820 public function display_errors($open = '<p>', $close = '</p>')
Derek Allard2067d1a2008-11-13 22:59:24 +00001821 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001822 return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001823 }
1824
1825}