blob: edd13372d9e1f23c32dec826ef581db42cc87c12 [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
Andrey Andreev1924e872016-01-11 12:55:34 +020031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://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 {
Andrey Andreeveac4adf2016-03-22 11:24:14 +0200459 if (in_array($key, array('wm_font_color', 'wm_shadow_color'), TRUE))
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200460 {
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 }
Andrey Andreeveac4adf2016-03-22 11:24:14 +0200481 elseif (in_array($key, array('width', 'height'), TRUE) && ! ctype_digit((string) $val))
482 {
483 continue;
484 }
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200485
486 $this->$key = $val;
487 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 }
489 }
490
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200491 // Is there a source image? If not, there's no reason to continue
Alex Bilbied261b1e2012-06-02 11:12:16 +0100492 if ($this->source_image === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 {
494 $this->set_error('imglib_source_image_required');
Eric Barnesb1673362011-12-05 22:05:38 -0500495 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 }
497
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200498 /* Is getimagesize() available?
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 *
500 * We use it to determine the image properties (width/height).
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200501 * Note: We need to figure out how to determine image
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 * properties using ImageMagick and NetPBM
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 */
504 if ( ! function_exists('getimagesize'))
505 {
506 $this->set_error('imglib_gd_required_for_props');
507 return FALSE;
508 }
509
510 $this->image_library = strtolower($this->image_library);
511
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200512 /* Set the full server path
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 *
514 * The source image may or may not contain a path.
515 * Either way, we'll try use realpath to generate the
516 * full server path in order to more reliably read it.
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 */
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200518 if (($full_source_path = realpath($this->source_image)) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200520 $full_source_path = str_replace('\\', '/', $full_source_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 }
522 else
523 {
524 $full_source_path = $this->source_image;
525 }
526
527 $x = explode('/', $full_source_path);
528 $this->source_image = end($x);
529 $this->source_folder = str_replace($this->source_image, '', $full_source_path);
530
531 // Set the Image Properties
532 if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
533 {
Eric Barnesb1673362011-12-05 22:05:38 -0500534 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 }
536
537 /*
538 * Assign the "new" image name/path
539 *
540 * If the user has set a "new_image" name it means
541 * we are making a copy of the source image. If not
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200542 * it means we are altering the original. We'll
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 * set the destination filename and path accordingly.
Derek Allard2067d1a2008-11-13 22:59:24 +0000544 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100545 if ($this->new_image === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 {
547 $this->dest_image = $this->source_image;
548 $this->dest_folder = $this->source_folder;
549 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200550 elseif (strpos($this->new_image, '/') === FALSE)
551 {
552 $this->dest_folder = $this->source_folder;
553 $this->dest_image = $this->new_image;
554 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000555 else
556 {
Andrey Andreev1b815532012-04-03 16:06:03 +0300557 if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200559 $full_dest_path = str_replace('\\', '/', realpath($this->new_image));
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 }
561 else
562 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200563 $full_dest_path = $this->new_image;
564 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000565
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200566 // Is there a file name?
567 if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path))
568 {
569 $this->dest_folder = $full_dest_path.'/';
570 $this->dest_image = $this->source_image;
571 }
572 else
573 {
574 $x = explode('/', $full_dest_path);
575 $this->dest_image = end($x);
576 $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 }
578 }
579
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200580 /* Compile the finalized filenames/paths
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 *
582 * We'll create two master strings containing the
583 * full server path to the source image and the
584 * full server path to the destination image.
585 * We'll also split the destination image name
586 * so we can insert the thumbnail marker if needed.
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100588 if ($this->create_thumb === FALSE OR $this->thumb_marker === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 {
590 $this->thumb_marker = '';
591 }
592
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200593 $xp = $this->explode_name($this->dest_image);
Derek Allard2067d1a2008-11-13 22:59:24 +0000594
595 $filename = $xp['name'];
596 $file_ext = $xp['ext'];
597
598 $this->full_src_path = $this->source_folder.$this->source_image;
599 $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;
600
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200601 /* Should we maintain image proportions?
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 *
603 * When creating thumbs or copies, the target width/height
604 * might not be in correct proportion with the source
Andrey Andreev8e70b792012-01-12 20:19:24 +0200605 * image's width/height. We'll recalculate it here.
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100607 if ($this->maintain_ratio === TRUE && ($this->width !== 0 OR $this->height !== 0))
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 {
609 $this->image_reproportion();
610 }
611
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200612 /* Was a width and height specified?
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 *
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200614 * If the destination width/height was not submitted we
615 * will use the values from the actual file
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 */
Alex Bilbied261b1e2012-06-02 11:12:16 +0100617 if ($this->width === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +0200618 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000619 $this->width = $this->orig_width;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200620 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000621
Alex Bilbied261b1e2012-06-02 11:12:16 +0100622 if ($this->height === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +0200623 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 $this->height = $this->orig_height;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200625 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000626
627 // Set the quality
Andrey Andreev8e70b792012-01-12 20:19:24 +0200628 $this->quality = trim(str_replace('%', '', $this->quality));
Derek Allard2067d1a2008-11-13 22:59:24 +0000629
Andrey Andreev7a7ad782012-11-12 17:21:01 +0200630 if ($this->quality === '' OR $this->quality === 0 OR ! ctype_digit($this->quality))
Andrey Andreev8e70b792012-01-12 20:19:24 +0200631 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000632 $this->quality = 90;
Andrey Andreev8e70b792012-01-12 20:19:24 +0200633 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000634
635 // Set the x/y coordinates
Andrey Andreev5036c9c2012-06-04 15:34:56 +0300636 is_numeric($this->x_axis) OR $this->x_axis = 0;
637 is_numeric($this->y_axis) OR $this->y_axis = 0;
Derek Allard2067d1a2008-11-13 22:59:24 +0000638
639 // Watermark-related Stuff...
Alex Bilbied261b1e2012-06-02 11:12:16 +0100640 if ($this->wm_overlay_path !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000641 {
Andrey Andreev8e70b792012-01-12 20:19:24 +0200642 $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path));
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 }
644
Alex Bilbied261b1e2012-06-02 11:12:16 +0100645 if ($this->wm_shadow_color !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 {
647 $this->wm_use_drop_shadow = TRUE;
648 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100649 elseif ($this->wm_use_drop_shadow === TRUE && $this->wm_shadow_color === '')
Andrey Andreev64dbdfb2011-12-30 14:14:07 +0200650 {
651 $this->wm_use_drop_shadow = FALSE;
652 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000653
Alex Bilbied261b1e2012-06-02 11:12:16 +0100654 if ($this->wm_font_path !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000655 {
656 $this->wm_use_truetype = TRUE;
657 }
658
659 return TRUE;
660 }
661
662 // --------------------------------------------------------------------
663
664 /**
665 * Image Resize
666 *
667 * This is a wrapper function that chooses the proper
668 * resize function based on the protocol specified
669 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000670 * @return bool
671 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200672 public function resize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000673 {
Andrey Andreev1a9f52c2012-01-07 01:06:34 +0200674 $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000675 return $this->$protocol('resize');
676 }
677
678 // --------------------------------------------------------------------
679
680 /**
681 * Image Crop
682 *
683 * This is a wrapper function that chooses the proper
684 * cropping function based on the protocol specified
685 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 * @return bool
687 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200688 public function crop()
Derek Allard2067d1a2008-11-13 22:59:24 +0000689 {
Andrey Andreev5a67e3d2012-01-07 01:21:09 +0200690 $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000691 return $this->$protocol('crop');
692 }
693
694 // --------------------------------------------------------------------
695
696 /**
697 * Image Rotate
698 *
699 * This is a wrapper function that chooses the proper
700 * rotation function based on the protocol specified
701 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000702 * @return bool
703 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200704 public function rotate()
Derek Allard2067d1a2008-11-13 22:59:24 +0000705 {
706 // Allowed rotation values
707 $degs = array(90, 180, 270, 'vrt', 'hor');
708
Alex Bilbied261b1e2012-06-02 11:12:16 +0100709 if ($this->rotation_angle === '' OR ! in_array($this->rotation_angle, $degs))
Derek Allard2067d1a2008-11-13 22:59:24 +0000710 {
711 $this->set_error('imglib_rotation_angle_required');
Eric Barnesb1673362011-12-05 22:05:38 -0500712 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 }
714
715 // Reassign the width and height
Alex Bilbied261b1e2012-06-02 11:12:16 +0100716 if ($this->rotation_angle === 90 OR $this->rotation_angle === 270)
Derek Allard2067d1a2008-11-13 22:59:24 +0000717 {
718 $this->width = $this->orig_height;
719 $this->height = $this->orig_width;
720 }
721 else
722 {
723 $this->width = $this->orig_width;
724 $this->height = $this->orig_height;
725 }
726
Derek Allard2067d1a2008-11-13 22:59:24 +0000727 // Choose resizing function
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200728 if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm')
Derek Allard2067d1a2008-11-13 22:59:24 +0000729 {
730 $protocol = 'image_process_'.$this->image_library;
Derek Allard2067d1a2008-11-13 22:59:24 +0000731 return $this->$protocol('rotate');
732 }
733
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200734 return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
735 ? $this->image_mirror_gd()
736 : $this->image_rotate_gd();
Derek Allard2067d1a2008-11-13 22:59:24 +0000737 }
738
739 // --------------------------------------------------------------------
740
741 /**
742 * Image Process Using GD/GD2
743 *
744 * This function will resize or crop
745 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 * @param string
747 * @return bool
748 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200749 public function image_process_gd($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000750 {
751 $v2_override = FALSE;
752
753 // If the target width/height match the source, AND if the new file name is not equal to the old file name
754 // 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 +0100755 if ($this->dynamic_output === FALSE && $this->orig_width === $this->width && $this->orig_height === $this->height)
Derek Allard2067d1a2008-11-13 22:59:24 +0000756 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100757 if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000758 {
Andrey Andreev45965742014-08-27 20:40:11 +0300759 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000760 }
Andrey Andreeva92b9032011-12-24 19:05:58 +0200761
762 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000763 }
764
765 // Let's set up our values based on the action
Alex Bilbied261b1e2012-06-02 11:12:16 +0100766 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000767 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200768 // Reassign the source width/height if cropping
Derek Jones4b9c6292011-07-01 17:40:48 -0500769 $this->orig_width = $this->width;
Derek Allard2067d1a2008-11-13 22:59:24 +0000770 $this->orig_height = $this->height;
771
772 // GD 2.0 has a cropping bug so we'll test for it
773 if ($this->gd_version() !== FALSE)
774 {
775 $gd_version = str_replace('0', '', $this->gd_version());
Andrey Andreevd4818b72014-10-23 17:15:32 +0300776 $v2_override = ($gd_version == 2);
Derek Allard2067d1a2008-11-13 22:59:24 +0000777 }
778 }
779 else
780 {
781 // If resizing the x/y axis must be zero
782 $this->x_axis = 0;
783 $this->y_axis = 0;
784 }
785
Andrey Andreev10fb7d12015-08-03 10:05:29 +0300786 // Create the image handle
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 if ( ! ($src_img = $this->image_create_gd()))
788 {
789 return FALSE;
790 }
791
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200792 /* Create the image
793 *
794 * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
795 * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
796 * below should that ever prove inaccurate.
797 *
Alex Bilbied261b1e2012-06-02 11:12:16 +0100798 * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override === FALSE)
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200799 */
Andrey Andreev8e70b792012-01-12 20:19:24 +0200800 if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000801 {
802 $create = 'imagecreatetruecolor';
803 $copy = 'imagecopyresampled';
804 }
805 else
806 {
807 $create = 'imagecreate';
808 $copy = 'imagecopyresized';
809 }
810
811 $dst_img = $create($this->width, $this->height);
Derek Jones595bfd12010-08-20 10:28:22 -0500812
Alex Bilbied261b1e2012-06-02 11:12:16 +0100813 if ($this->image_type === 3) // png we can actually preserve transparency
Derek Jones595bfd12010-08-20 10:28:22 -0500814 {
815 imagealphablending($dst_img, FALSE);
816 imagesavealpha($dst_img, TRUE);
817 }
Barry Mienydd671972010-10-04 16:33:58 +0200818
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
820
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200821 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +0100822 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 {
824 $this->image_display_gd($dst_img);
825 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200826 elseif ( ! $this->image_save_gd($dst_img)) // Or save it
Derek Allard2067d1a2008-11-13 22:59:24 +0000827 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200828 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000829 }
830
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200831 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +0000832 imagedestroy($dst_img);
833 imagedestroy($src_img);
834
Andrey Andreev45965742014-08-27 20:40:11 +0300835 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000836
837 return TRUE;
838 }
839
840 // --------------------------------------------------------------------
841
842 /**
843 * Image Process Using ImageMagick
844 *
845 * This function will resize, crop or rotate
846 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000847 * @param string
848 * @return bool
849 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200850 public function image_process_imagemagick($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000851 {
Andrey Andreev3a197592015-05-21 01:05:06 +0300852 // Do we have a vaild library path?
Alex Bilbied261b1e2012-06-02 11:12:16 +0100853 if ($this->library_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000854 {
855 $this->set_error('imglib_libpath_invalid');
856 return FALSE;
857 }
858
Andrey Andreev8e70b792012-01-12 20:19:24 +0200859 if ( ! preg_match('/convert$/i', $this->library_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000860 {
Andrey Andreeva92b9032011-12-24 19:05:58 +0200861 $this->library_path = rtrim($this->library_path, '/').'/convert';
Derek Allard2067d1a2008-11-13 22:59:24 +0000862 }
863
864 // Execute the command
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200865 $cmd = $this->library_path.' -quality '.$this->quality;
Derek Allard2067d1a2008-11-13 22:59:24 +0000866
Alex Bilbied261b1e2012-06-02 11:12:16 +0100867 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 {
Andrey Andreev8e70b792012-01-12 20:19:24 +0200869 $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 +0000870 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100871 elseif ($action === 'rotate')
Derek Allard2067d1a2008-11-13 22:59:24 +0000872 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200873 $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
874 ? '-flop' : '-rotate '.$this->rotation_angle;
Derek Allard2067d1a2008-11-13 22:59:24 +0000875
Andrey Andreev8e70b792012-01-12 20:19:24 +0200876 $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
Derek Allard2067d1a2008-11-13 22:59:24 +0000877 }
Andrey Andreev8e70b792012-01-12 20:19:24 +0200878 else // Resize
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 {
Omar24063af2012-07-02 13:50:17 -0300880 if($this->maintain_ratio === TRUE)
881 {
882 $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
883 }
Omarbb531d62012-06-29 10:48:28 -0300884 else
Omar24063af2012-07-02 13:50:17 -0300885 {
886 $cmd .= ' -resize '.$this->width.'x'.$this->height.'\! "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1';
887 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000888 }
889
890 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200891 // exec() might be disabled
892 if (function_usable('exec'))
893 {
894 @exec($cmd, $output, $retval);
895 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000896
Andrey Andreev8e70b792012-01-12 20:19:24 +0200897 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000898 if ($retval > 0)
899 {
900 $this->set_error('imglib_image_process_failed');
901 return FALSE;
902 }
903
Andrey Andreev45965742014-08-27 20:40:11 +0300904 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000905
906 return TRUE;
907 }
908
909 // --------------------------------------------------------------------
910
911 /**
912 * Image Process Using NetPBM
913 *
914 * This function will resize, crop or rotate
915 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 * @param string
917 * @return bool
918 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200919 public function image_process_netpbm($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100921 if ($this->library_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000922 {
923 $this->set_error('imglib_libpath_invalid');
924 return FALSE;
925 }
926
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200927 // Build the resizing command
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 switch ($this->image_type)
929 {
930 case 1 :
Andrey Andreev56454792012-05-17 14:32:19 +0300931 $cmd_in = 'giftopnm';
932 $cmd_out = 'ppmtogif';
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 break;
934 case 2 :
Andrey Andreev56454792012-05-17 14:32:19 +0300935 $cmd_in = 'jpegtopnm';
936 $cmd_out = 'ppmtojpeg';
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 break;
938 case 3 :
Andrey Andreev56454792012-05-17 14:32:19 +0300939 $cmd_in = 'pngtopnm';
940 $cmd_out = 'ppmtopng';
Derek Allard2067d1a2008-11-13 22:59:24 +0000941 break;
942 }
943
Alex Bilbied261b1e2012-06-02 11:12:16 +0100944 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000945 {
946 $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
947 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100948 elseif ($action === 'rotate')
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 {
950 switch ($this->rotation_angle)
951 {
Andrey Andreev56454792012-05-17 14:32:19 +0300952 case 90: $angle = 'r270';
Derek Allard2067d1a2008-11-13 22:59:24 +0000953 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300954 case 180: $angle = 'r180';
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300956 case 270: $angle = 'r90';
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300958 case 'vrt': $angle = 'tb';
Derek Allard2067d1a2008-11-13 22:59:24 +0000959 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300960 case 'hor': $angle = 'lr';
Derek Allard2067d1a2008-11-13 22:59:24 +0000961 break;
962 }
963
964 $cmd_inner = 'pnmflip -'.$angle.' ';
965 }
966 else // Resize
967 {
968 $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
969 }
970
971 $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
972
973 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200974 // exec() might be disabled
975 if (function_usable('exec'))
976 {
977 @exec($cmd, $output, $retval);
978 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000979
Andrey Andreev8e70b792012-01-12 20:19:24 +0200980 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000981 if ($retval > 0)
982 {
983 $this->set_error('imglib_image_process_failed');
984 return FALSE;
985 }
986
987 // With NetPBM we have to create a temporary image.
988 // If you try manipulating the original it fails so
989 // we have to rename the temp file.
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200990 copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200991 unlink($this->dest_folder.'netpbm.tmp');
Andrey Andreev45965742014-08-27 20:40:11 +0300992 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000993
994 return TRUE;
995 }
996
997 // --------------------------------------------------------------------
998
999 /**
1000 * Image Rotate Using GD
1001 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001002 * @return bool
1003 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001004 public function image_rotate_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001005 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001006 // Create the image handle
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 if ( ! ($src_img = $this->image_create_gd()))
1008 {
1009 return FALSE;
1010 }
1011
1012 // Set the background color
1013 // This won't work with transparent PNG files so we are
1014 // going to have to figure out how to determine the color
1015 // of the alpha channel in a future release.
1016
Andrey Andreev3a197592015-05-21 01:05:06 +03001017 $white = imagecolorallocate($src_img, 255, 255, 255);
Derek Allard2067d1a2008-11-13 22:59:24 +00001018
Andrey Andreev8e70b792012-01-12 20:19:24 +02001019 // Rotate it!
Derek Allard2067d1a2008-11-13 22:59:24 +00001020 $dst_img = imagerotate($src_img, $this->rotation_angle, $white);
1021
Andrey Andreev8e70b792012-01-12 20:19:24 +02001022 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001023 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001024 {
1025 $this->image_display_gd($dst_img);
1026 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001027 elseif ( ! $this->image_save_gd($dst_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001028 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001029 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 }
1031
Andrey Andreev8e70b792012-01-12 20:19:24 +02001032 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001033 imagedestroy($dst_img);
1034 imagedestroy($src_img);
1035
Andrey Andreev45965742014-08-27 20:40:11 +03001036 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001037
Pascal Kriete8761ef52011-02-14 13:13:52 -05001038 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001039 }
1040
1041 // --------------------------------------------------------------------
1042
1043 /**
1044 * Create Mirror Image using GD
1045 *
1046 * This function will flip horizontal or vertical
1047 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001048 * @return bool
1049 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001050 public function image_mirror_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001051 {
1052 if ( ! $src_img = $this->image_create_gd())
1053 {
1054 return FALSE;
1055 }
1056
Derek Jones4b9c6292011-07-01 17:40:48 -05001057 $width = $this->orig_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001058 $height = $this->orig_height;
1059
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001060 if ($this->rotation_angle === 'hor')
Derek Allard2067d1a2008-11-13 22:59:24 +00001061 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001062 for ($i = 0; $i < $height; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001063 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001064 $left = 0;
1065 $right = $width - 1;
1066
Derek Allard2067d1a2008-11-13 22:59:24 +00001067 while ($left < $right)
1068 {
1069 $cl = imagecolorat($src_img, $left, $i);
1070 $cr = imagecolorat($src_img, $right, $i);
1071
1072 imagesetpixel($src_img, $left, $i, $cr);
1073 imagesetpixel($src_img, $right, $i, $cl);
1074
1075 $left++;
1076 $right--;
1077 }
1078 }
1079 }
1080 else
1081 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001082 for ($i = 0; $i < $width; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001083 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001084 $top = 0;
1085 $bottom = $height - 1;
1086
Andrey Andreev5d78fd82015-05-11 18:19:01 +03001087 while ($top < $bottom)
Derek Allard2067d1a2008-11-13 22:59:24 +00001088 {
1089 $ct = imagecolorat($src_img, $i, $top);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001090 $cb = imagecolorat($src_img, $i, $bottom);
Derek Allard2067d1a2008-11-13 22:59:24 +00001091
1092 imagesetpixel($src_img, $i, $top, $cb);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001093 imagesetpixel($src_img, $i, $bottom, $ct);
Derek Allard2067d1a2008-11-13 22:59:24 +00001094
1095 $top++;
Andrey Andreevfbde2792015-05-11 11:03:06 +03001096 $bottom--;
Derek Allard2067d1a2008-11-13 22:59:24 +00001097 }
1098 }
1099 }
1100
Andrey Andreev8e70b792012-01-12 20:19:24 +02001101 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001102 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 {
1104 $this->image_display_gd($src_img);
1105 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001106 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001108 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 }
1110
Andrey Andreev8e70b792012-01-12 20:19:24 +02001111 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001112 imagedestroy($src_img);
1113
Andrey Andreev45965742014-08-27 20:40:11 +03001114 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001115
1116 return TRUE;
1117 }
1118
1119 // --------------------------------------------------------------------
1120
1121 /**
1122 * Image Watermark
1123 *
1124 * This is a wrapper function that chooses the type
1125 * of watermarking based on the specified preference.
1126 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001127 * @return bool
1128 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001129 public function watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001130 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001131 return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
Derek Allard2067d1a2008-11-13 22:59:24 +00001132 }
1133
1134 // --------------------------------------------------------------------
1135
1136 /**
1137 * Watermark - Graphic Version
1138 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 * @return bool
1140 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001141 public function overlay_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001142 {
1143 if ( ! function_exists('imagecolortransparent'))
1144 {
1145 $this->set_error('imglib_gd_required');
1146 return FALSE;
1147 }
1148
Andrey Andreev8e70b792012-01-12 20:19:24 +02001149 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001150 $this->get_image_properties();
1151
Andrey Andreev8e70b792012-01-12 20:19:24 +02001152 // Fetch watermark image properties
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001153 $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001154 $wm_img_type = $props['image_type'];
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001155 $wm_width = $props['width'];
1156 $wm_height = $props['height'];
Derek Allard2067d1a2008-11-13 22:59:24 +00001157
Andrey Andreev8e70b792012-01-12 20:19:24 +02001158 // Create two image resources
Derek Jones4b9c6292011-07-01 17:40:48 -05001159 $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001160 $src_img = $this->image_create_gd($this->full_src_path);
1161
1162 // Reverse the offset if necessary
1163 // When the image is positioned at the bottom
1164 // we don't want the vertical offset to push it
Andrey Andreev8e70b792012-01-12 20:19:24 +02001165 // further down. We want the reverse, so we'll
1166 // invert the offset. Same with the horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001167 // offset when the image is at the right
1168
Andrey Andreev8e70b792012-01-12 20:19:24 +02001169 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1170 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001171
Alex Bilbied261b1e2012-06-02 11:12:16 +01001172 if ($this->wm_vrt_alignment === 'B')
Derek Allard2067d1a2008-11-13 22:59:24 +00001173 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
1174
Alex Bilbied261b1e2012-06-02 11:12:16 +01001175 if ($this->wm_hor_alignment === 'R')
Derek Allard2067d1a2008-11-13 22:59:24 +00001176 $this->wm_hor_offset = $this->wm_hor_offset * -1;
1177
Andrey Andreev8e70b792012-01-12 20:19:24 +02001178 // Set the base x and y axis values
Derek Allard2067d1a2008-11-13 22:59:24 +00001179 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1180 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1181
Andrey Andreev8e70b792012-01-12 20:19:24 +02001182 // Set the vertical position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001183 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001184 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001185 $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
1186 }
1187 elseif ($this->wm_vrt_alignment === 'B')
1188 {
1189 $y_axis += $this->orig_height - $wm_height;
Derek Allard2067d1a2008-11-13 22:59:24 +00001190 }
1191
Andrey Andreev8e70b792012-01-12 20:19:24 +02001192 // Set the horizontal position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001193 if ($this->wm_hor_alignment === 'C')
Derek Allard2067d1a2008-11-13 22:59:24 +00001194 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001195 $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
1196 }
1197 elseif ($this->wm_hor_alignment === 'R')
1198 {
1199 $x_axis += $this->orig_width - $wm_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001200 }
1201
Andrey Andreev10fb7d12015-08-03 10:05:29 +03001202 // Build the finalized image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001203 if ($wm_img_type === 3 && function_exists('imagealphablending'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001204 {
1205 @imagealphablending($src_img, TRUE);
Barry Mienydd671972010-10-04 16:33:58 +02001206 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001207
1208 // Set RGB values for text and shadow
1209 $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
1210 $alpha = ($rgba & 0x7F000000) >> 24;
1211
1212 // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency
1213 if ($alpha > 0)
1214 {
1215 // copy the image directly, the image's alpha transparency being the sole determinant of blending
1216 imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
1217 }
1218 else
1219 {
1220 // set our RGB value from above to be transparent and merge the images with the specified opacity
1221 imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp));
1222 imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
1223 }
1224
Andrey Andreevdb037db2015-01-12 13:45:12 +02001225 // We can preserve transparency for PNG images
Дмитрийb23b8fc2014-10-20 00:36:55 +04001226 if ($this->image_type === 3)
1227 {
1228 imagealphablending($src_img, FALSE);
1229 imagesavealpha($src_img, TRUE);
1230 }
1231
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001232 // Output the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001233 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001234 {
1235 $this->image_display_gd($src_img);
1236 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001237 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001238 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001239 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001240 }
1241
1242 imagedestroy($src_img);
1243 imagedestroy($wm_img);
1244
1245 return TRUE;
1246 }
1247
1248 // --------------------------------------------------------------------
1249
1250 /**
1251 * Watermark - Text Version
1252 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001253 * @return bool
1254 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001255 public function text_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001256 {
1257 if ( ! ($src_img = $this->image_create_gd()))
1258 {
1259 return FALSE;
1260 }
1261
Alex Bilbied261b1e2012-06-02 11:12:16 +01001262 if ($this->wm_use_truetype === TRUE && ! file_exists($this->wm_font_path))
Derek Allard2067d1a2008-11-13 22:59:24 +00001263 {
1264 $this->set_error('imglib_missing_font');
1265 return FALSE;
1266 }
1267
Andrey Andreev8e70b792012-01-12 20:19:24 +02001268 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001269 $this->get_image_properties();
1270
Derek Allard2067d1a2008-11-13 22:59:24 +00001271 // Reverse the vertical offset
1272 // When the image is positioned at the bottom
1273 // we don't want the vertical offset to push it
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001274 // further down. We want the reverse, so we'll
Andrey Andreev8e70b792012-01-12 20:19:24 +02001275 // invert the offset. Note: The horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 // offset flips itself automatically
1277
Alex Bilbied261b1e2012-06-02 11:12:16 +01001278 if ($this->wm_vrt_alignment === 'B')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001279 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001280 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001281 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001282
Alex Bilbied261b1e2012-06-02 11:12:16 +01001283 if ($this->wm_hor_alignment === 'R')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001284 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001285 $this->wm_hor_offset = $this->wm_hor_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001286 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001287
1288 // Set font width and height
1289 // These are calculated differently depending on
1290 // whether we are using the true type font or not
Alex Bilbied261b1e2012-06-02 11:12:16 +01001291 if ($this->wm_use_truetype === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001292 {
Andrey Andreeve52fc262014-02-11 13:27:01 +02001293 if (empty($this->wm_font_size))
Andrey Andreeva92b9032011-12-24 19:05:58 +02001294 {
1295 $this->wm_font_size = 17;
1296 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001297
Andrey Andreeve52fc262014-02-11 13:27:01 +02001298 if (function_exists('imagettfbbox'))
1299 {
1300 $temp = imagettfbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text);
1301 $temp = $temp[2] - $temp[0];
1302
1303 $fontwidth = $temp / strlen($this->wm_text);
1304 }
1305 else
1306 {
1307 $fontwidth = $this->wm_font_size - ($this->wm_font_size / 4);
1308 }
1309
Derek Allard2067d1a2008-11-13 22:59:24 +00001310 $fontheight = $this->wm_font_size;
1311 $this->wm_vrt_offset += $this->wm_font_size;
1312 }
1313 else
1314 {
Derek Jones4b9c6292011-07-01 17:40:48 -05001315 $fontwidth = imagefontwidth($this->wm_font_size);
Derek Allard2067d1a2008-11-13 22:59:24 +00001316 $fontheight = imagefontheight($this->wm_font_size);
1317 }
1318
1319 // Set base X and Y axis values
1320 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1321 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1322
Alex Bilbied261b1e2012-06-02 11:12:16 +01001323 if ($this->wm_use_drop_shadow === FALSE)
omar0779e992015-01-31 11:57:07 -07001324 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001325 $this->wm_shadow_distance = 0;
omar0779e992015-01-31 11:57:07 -07001326 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001327
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001328 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1329 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001330
omar0779e992015-01-31 11:57:07 -07001331 // Set vertical alignment
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001332 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001333 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001334 $y_axis += ($this->orig_height / 2) + ($fontheight / 2);
1335 }
1336 elseif ($this->wm_vrt_alignment === 'B')
1337 {
1338 $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2);
Derek Allard2067d1a2008-11-13 22:59:24 +00001339 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001340
omar0779e992015-01-31 11:57:07 -07001341 // Set horizontal alignment
1342 if ($this->wm_hor_alignment === 'R')
1343 {
omar9c855322015-01-31 11:58:03 -07001344 $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)) - $this->wm_shadow_distance;
omar0779e992015-01-31 11:57:07 -07001345 }
1346 elseif ($this->wm_hor_alignment === 'C')
1347 {
1348 $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
1349 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001350
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001351 if ($this->wm_use_drop_shadow)
Derek Allard2067d1a2008-11-13 22:59:24 +00001352 {
omar0779e992015-01-31 11:57:07 -07001353 // Offset from text
1354 $x_shad = $x_axis + $this->wm_shadow_distance;
1355 $y_shad = $y_axis + $this->wm_shadow_distance;
Andrey Andreev3a197592015-05-21 01:05:06 +03001356
omar0779e992015-01-31 11:57:07 -07001357 /* Set RGB values for shadow
Andrey Andreev8323ae62011-12-31 18:39:10 +02001358 *
1359 * First character is #, so we don't really need it.
1360 * Get the rest of the string and split it into 2-length
1361 * hex values:
1362 */
Andrey Andreev8323ae62011-12-31 18:39:10 +02001363 $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2);
Ronald Beilsma8f80bc42012-01-12 16:41:49 +01001364 $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2]));
Andrey Andreev3a197592015-05-21 01:05:06 +03001365
omar0779e992015-01-31 11:57:07 -07001366 // Add the shadow to the source image
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001367 if ($this->wm_use_truetype)
1368 {
1369 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 +02001370 }
1371 else
1372 {
1373 imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001374 }
omar0779e992015-01-31 11:57:07 -07001375 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001376
omar0779e992015-01-31 11:57:07 -07001377 /* Set RGB values for text
1378 *
1379 * First character is #, so we don't really need it.
1380 * Get the rest of the string and split it into 2-length
1381 * hex values:
1382 */
1383 $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2);
1384 $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2]));
Andrey Andreev99ae2262012-10-05 15:14:30 +03001385
omar0779e992015-01-31 11:57:07 -07001386 // Add the text to the source image
1387 if ($this->wm_use_truetype)
1388 {
1389 imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text);
1390 }
1391 else
1392 {
1393 imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
1394 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001395
omar0779e992015-01-31 11:57:07 -07001396 // We can preserve transparency for PNG images
1397 if ($this->image_type === 3)
1398 {
1399 imagealphablending($src_img, FALSE);
1400 imagesavealpha($src_img, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001401 }
1402
Andrey Andreev8e70b792012-01-12 20:19:24 +02001403 // Output the final image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001404 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001405 {
1406 $this->image_display_gd($src_img);
1407 }
1408 else
1409 {
1410 $this->image_save_gd($src_img);
1411 }
1412
1413 imagedestroy($src_img);
1414
1415 return TRUE;
1416 }
1417
1418 // --------------------------------------------------------------------
1419
1420 /**
1421 * Create Image - GD
1422 *
1423 * This simply creates an image resource handle
1424 * based on the type of image being processed
1425 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001426 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001427 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001428 * @return resource
1429 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001430 public function image_create_gd($path = '', $image_type = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001431 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001432 if ($path === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001433 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001434 $path = $this->full_src_path;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001435 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001436
Alex Bilbied261b1e2012-06-02 11:12:16 +01001437 if ($image_type === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001438 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001439 $image_type = $this->image_type;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001440 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001441
Derek Allard2067d1a2008-11-13 22:59:24 +00001442 switch ($image_type)
1443 {
Andrey Andreev3a197592015-05-21 01:05:06 +03001444 case 1:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001445 if ( ! function_exists('imagecreatefromgif'))
1446 {
1447 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1448 return FALSE;
1449 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001450
Andrey Andreeve52fc262014-02-11 13:27:01 +02001451 return imagecreatefromgif($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001452 case 2:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001453 if ( ! function_exists('imagecreatefromjpeg'))
1454 {
1455 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1456 return FALSE;
1457 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001458
Andrey Andreeve52fc262014-02-11 13:27:01 +02001459 return imagecreatefromjpeg($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001460 case 3:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001461 if ( ! function_exists('imagecreatefrompng'))
1462 {
1463 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1464 return FALSE;
1465 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001466
Andrey Andreeve52fc262014-02-11 13:27:01 +02001467 return imagecreatefrompng($path);
1468 default:
1469 $this->set_error(array('imglib_unsupported_imagecreate'));
1470 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001471 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001472 }
1473
1474 // --------------------------------------------------------------------
1475
1476 /**
1477 * Write image file to disk - GD
1478 *
1479 * Takes an image resource as input and writes the file
1480 * to the specified destination
1481 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001482 * @param resource
1483 * @return bool
1484 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001485 public function image_save_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001486 {
1487 switch ($this->image_type)
1488 {
Andrey Andreev56454792012-05-17 14:32:19 +03001489 case 1:
1490 if ( ! function_exists('imagegif'))
1491 {
1492 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1493 return FALSE;
1494 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001495
Andrey Andreev56454792012-05-17 14:32:19 +03001496 if ( ! @imagegif($resource, $this->full_dst_path))
1497 {
1498 $this->set_error('imglib_save_failed');
1499 return FALSE;
1500 }
1501 break;
1502 case 2:
1503 if ( ! function_exists('imagejpeg'))
1504 {
1505 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1506 return FALSE;
1507 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001508
Andrey Andreev56454792012-05-17 14:32:19 +03001509 if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
1510 {
1511 $this->set_error('imglib_save_failed');
1512 return FALSE;
1513 }
1514 break;
1515 case 3:
1516 if ( ! function_exists('imagepng'))
1517 {
1518 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1519 return FALSE;
1520 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001521
Andrey Andreev56454792012-05-17 14:32:19 +03001522 if ( ! @imagepng($resource, $this->full_dst_path))
1523 {
1524 $this->set_error('imglib_save_failed');
1525 return FALSE;
1526 }
1527 break;
1528 default:
1529 $this->set_error(array('imglib_unsupported_imagecreate'));
1530 return FALSE;
1531 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001532 }
1533
1534 return TRUE;
1535 }
1536
1537 // --------------------------------------------------------------------
1538
1539 /**
1540 * Dynamically outputs an image
1541 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001542 * @param resource
1543 * @return void
1544 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001545 public function image_display_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001546 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001547 header('Content-Disposition: filename='.$this->source_image.';');
1548 header('Content-Type: '.$this->mime_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001549 header('Content-Transfer-Encoding: binary');
1550 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
1551
1552 switch ($this->image_type)
1553 {
Andrey Andreev56454792012-05-17 14:32:19 +03001554 case 1 : imagegif($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001555 break;
Ted Wood9cc707b2013-01-08 19:41:45 -08001556 case 2 : imagejpeg($resource, NULL, $this->quality);
Derek Allard2067d1a2008-11-13 22:59:24 +00001557 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001558 case 3 : imagepng($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001559 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001560 default: echo 'Unable to display the image';
Derek Allard2067d1a2008-11-13 22:59:24 +00001561 break;
1562 }
1563 }
1564
1565 // --------------------------------------------------------------------
1566
1567 /**
1568 * Re-proportion Image Width/Height
1569 *
1570 * When creating thumbs, the desired width/height
1571 * can end up warping the image due to an incorrect
1572 * ratio between the full-sized image and the thumb.
1573 *
1574 * This function lets us re-proportion the width/height
1575 * if users choose to maintain the aspect ratio when resizing.
1576 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001577 * @return void
1578 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001579 public function image_reproportion()
Derek Allard2067d1a2008-11-13 22:59:24 +00001580 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001581 if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001582 OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
1583 OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
Derek Allard2067d1a2008-11-13 22:59:24 +00001584 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001585 return;
Derek Allard2067d1a2008-11-13 22:59:24 +00001586 }
1587
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001588 // Sanitize
Andrey Andreev8e70b792012-01-12 20:19:24 +02001589 $this->width = (int) $this->width;
1590 $this->height = (int) $this->height;
1591
1592 if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
Derek Allard2067d1a2008-11-13 22:59:24 +00001593 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001594 if ($this->width > 0 && $this->height > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001595 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001596 $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
1597 ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001598 }
1599 else
1600 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001601 $this->master_dim = ($this->height === 0) ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001602 }
1603 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001604 elseif (($this->master_dim === 'width' && $this->width === 0)
1605 OR ($this->master_dim === 'height' && $this->height === 0))
1606 {
1607 return;
1608 }
1609
1610 if ($this->master_dim === 'width')
1611 {
1612 $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
1613 }
1614 else
1615 {
1616 $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
1617 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001618 }
1619
1620 // --------------------------------------------------------------------
1621
1622 /**
1623 * Get image properties
1624 *
1625 * A helper function that gets info about the file
1626 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001627 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001628 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001629 * @return mixed
1630 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001631 public function get_image_properties($path = '', $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001632 {
1633 // For now we require GD but we should
1634 // find a way to determine this using IM or NetPBM
1635
Alex Bilbied261b1e2012-06-02 11:12:16 +01001636 if ($path === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +02001637 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001638 $path = $this->full_src_path;
Andrey Andreev8e70b792012-01-12 20:19:24 +02001639 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001640
1641 if ( ! file_exists($path))
1642 {
1643 $this->set_error('imglib_invalid_path');
1644 return FALSE;
1645 }
1646
Phil Sturgeon901998a2011-08-26 10:03:33 +01001647 $vals = getimagesize($path);
Derek Allard2067d1a2008-11-13 22:59:24 +00001648 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
Andrey Andreeva92b9032011-12-24 19:05:58 +02001649 $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001650
Alex Bilbied261b1e2012-06-02 11:12:16 +01001651 if ($return === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001652 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001653 return array(
1654 'width' => $vals[0],
1655 'height' => $vals[1],
1656 'image_type' => $vals[2],
1657 'size_str' => $vals[3],
1658 'mime_type' => $mime
1659 );
Derek Allard2067d1a2008-11-13 22:59:24 +00001660 }
1661
Andrey Andreeva92b9032011-12-24 19:05:58 +02001662 $this->orig_width = $vals[0];
1663 $this->orig_height = $vals[1];
1664 $this->image_type = $vals[2];
1665 $this->size_str = $vals[3];
Derek Allard2067d1a2008-11-13 22:59:24 +00001666 $this->mime_type = $mime;
1667
1668 return TRUE;
1669 }
1670
1671 // --------------------------------------------------------------------
1672
1673 /**
1674 * Size calculator
1675 *
1676 * This function takes a known width x height and
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001677 * recalculates it to a new size. Only one
Derek Allard2067d1a2008-11-13 22:59:24 +00001678 * new variable needs to be known
1679 *
1680 * $props = array(
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001681 * 'width' => $width,
1682 * 'height' => $height,
1683 * 'new_width' => 40,
1684 * 'new_height' => ''
1685 * );
Derek Allard2067d1a2008-11-13 22:59:24 +00001686 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001687 * @param array
1688 * @return array
1689 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001690 public function size_calculator($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001691 {
1692 if ( ! is_array($vals))
1693 {
1694 return;
1695 }
1696
1697 $allowed = array('new_width', 'new_height', 'width', 'height');
1698
1699 foreach ($allowed as $item)
1700 {
Andrey Andreev56454792012-05-17 14:32:19 +03001701 if (empty($vals[$item]))
1702 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001703 $vals[$item] = 0;
Andrey Andreev56454792012-05-17 14:32:19 +03001704 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001705 }
1706
Alex Bilbied261b1e2012-06-02 11:12:16 +01001707 if ($vals['width'] === 0 OR $vals['height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001708 {
1709 return $vals;
1710 }
1711
Alex Bilbied261b1e2012-06-02 11:12:16 +01001712 if ($vals['new_width'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001713 {
1714 $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
1715 }
Alex Bilbied261b1e2012-06-02 11:12:16 +01001716 elseif ($vals['new_height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001717 {
1718 $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
1719 }
1720
1721 return $vals;
1722 }
1723
1724 // --------------------------------------------------------------------
1725
1726 /**
1727 * Explode source_image
1728 *
1729 * This is a helper function that extracts the extension
Derek Jones4b9c6292011-07-01 17:40:48 -05001730 * from the source_image. This function lets us deal with
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001731 * source_images with multiple periods, like: my.cool.jpg
Derek Allard2067d1a2008-11-13 22:59:24 +00001732 * It returns an associative array with two elements:
Derek Jones4b9c6292011-07-01 17:40:48 -05001733 * $array['ext'] = '.jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001734 * $array['name'] = 'my.cool';
1735 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001736 * @param array
1737 * @return array
1738 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001739 public function explode_name($source_image)
Derek Allard2067d1a2008-11-13 22:59:24 +00001740 {
Derek Jones08cae632009-02-10 20:03:29 +00001741 $ext = strrchr($source_image, '.');
1742 $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext));
Barry Mienydd671972010-10-04 16:33:58 +02001743
Derek Jones08cae632009-02-10 20:03:29 +00001744 return array('ext' => $ext, 'name' => $name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001745 }
1746
1747 // --------------------------------------------------------------------
1748
1749 /**
1750 * Is GD Installed?
1751 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001752 * @return bool
1753 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001754 public function gd_loaded()
Derek Allard2067d1a2008-11-13 22:59:24 +00001755 {
1756 if ( ! extension_loaded('gd'))
1757 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001758 /* As it is stated in the PHP manual, dl() is not always available
1759 * and even if so - it could generate an E_WARNING message on failure
1760 */
Andrey Andreev8e70b792012-01-12 20:19:24 +02001761 return (function_exists('dl') && @dl('gd.so'));
Derek Allard2067d1a2008-11-13 22:59:24 +00001762 }
1763
1764 return TRUE;
1765 }
1766
1767 // --------------------------------------------------------------------
1768
1769 /**
1770 * Get GD version
1771 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001772 * @return mixed
1773 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001774 public function gd_version()
Derek Allard2067d1a2008-11-13 22:59:24 +00001775 {
1776 if (function_exists('gd_info'))
1777 {
1778 $gd_version = @gd_info();
Andrey Andreev8e70b792012-01-12 20:19:24 +02001779 return preg_replace('/\D/', '', $gd_version['GD Version']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001780 }
1781
1782 return FALSE;
1783 }
1784
1785 // --------------------------------------------------------------------
1786
1787 /**
1788 * Set error message
1789 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001790 * @param string
1791 * @return void
1792 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001793 public function set_error($msg)
Derek Allard2067d1a2008-11-13 22:59:24 +00001794 {
1795 $CI =& get_instance();
1796 $CI->lang->load('imglib');
1797
1798 if (is_array($msg))
1799 {
1800 foreach ($msg as $val)
1801 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001802 $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001803 $this->error_msg[] = $msg;
1804 log_message('error', $msg);
1805 }
1806 }
1807 else
1808 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001809 $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg);
Derek Allard2067d1a2008-11-13 22:59:24 +00001810 $this->error_msg[] = $msg;
1811 log_message('error', $msg);
1812 }
1813 }
1814
1815 // --------------------------------------------------------------------
1816
1817 /**
1818 * Show error messages
1819 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001820 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001821 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001822 * @return string
1823 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001824 public function display_errors($open = '<p>', $close = '</p>')
Derek Allard2067d1a2008-11-13 22:59:24 +00001825 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001826 return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001827 }
1828
1829}