blob: 06cdde0b890bbcf5f05dea20b69f08087f130709 [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 Andreevb3f69342016-03-22 11:31:58 +0200869 $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis;
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 Andreevb3f69342016-03-22 11:31:58 +0200873 $cmd .= ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt')
874 ? ' -flop'
875 : ' -rotate '.$this->rotation_angle;
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 }
Andrey Andreev8e70b792012-01-12 20:19:24 +0200877 else // Resize
Derek Allard2067d1a2008-11-13 22:59:24 +0000878 {
Omar24063af2012-07-02 13:50:17 -0300879 if($this->maintain_ratio === TRUE)
880 {
Andrey Andreevb3f69342016-03-22 11:31:58 +0200881 $cmd .= ' -resize '.$this->width.'x'.$this->height;
Omar24063af2012-07-02 13:50:17 -0300882 }
Omarbb531d62012-06-29 10:48:28 -0300883 else
Omar24063af2012-07-02 13:50:17 -0300884 {
Andrey Andreevb3f69342016-03-22 11:31:58 +0200885 $cmd .= ' -resize '.$this->width.'x'.$this->height.'\!';
Omar24063af2012-07-02 13:50:17 -0300886 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000887 }
888
Andrey Andreevbe8bd922016-11-07 12:31:31 +0200889 $cmd .= ' '.escapeshellarg($this->full_src_path).' '.escapeshellarg($this->full_dst_path).' 2>&1';
Andrey Andreevb3f69342016-03-22 11:31:58 +0200890
Derek Allard2067d1a2008-11-13 22:59:24 +0000891 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200892 // exec() might be disabled
893 if (function_usable('exec'))
894 {
895 @exec($cmd, $output, $retval);
896 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000897
Andrey Andreev8e70b792012-01-12 20:19:24 +0200898 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 if ($retval > 0)
900 {
901 $this->set_error('imglib_image_process_failed');
902 return FALSE;
903 }
904
Andrey Andreev45965742014-08-27 20:40:11 +0300905 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000906
907 return TRUE;
908 }
909
910 // --------------------------------------------------------------------
911
912 /**
913 * Image Process Using NetPBM
914 *
915 * This function will resize, crop or rotate
916 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000917 * @param string
918 * @return bool
919 */
Andrey Andreev4eea9892011-12-19 12:05:41 +0200920 public function image_process_netpbm($action = 'resize')
Derek Allard2067d1a2008-11-13 22:59:24 +0000921 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100922 if ($this->library_path === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000923 {
924 $this->set_error('imglib_libpath_invalid');
925 return FALSE;
926 }
927
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200928 // Build the resizing command
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 switch ($this->image_type)
930 {
931 case 1 :
Andrey Andreev56454792012-05-17 14:32:19 +0300932 $cmd_in = 'giftopnm';
933 $cmd_out = 'ppmtogif';
Derek Allard2067d1a2008-11-13 22:59:24 +0000934 break;
935 case 2 :
Andrey Andreev56454792012-05-17 14:32:19 +0300936 $cmd_in = 'jpegtopnm';
937 $cmd_out = 'ppmtojpeg';
Derek Allard2067d1a2008-11-13 22:59:24 +0000938 break;
939 case 3 :
Andrey Andreev56454792012-05-17 14:32:19 +0300940 $cmd_in = 'pngtopnm';
941 $cmd_out = 'ppmtopng';
Derek Allard2067d1a2008-11-13 22:59:24 +0000942 break;
943 }
944
Alex Bilbied261b1e2012-06-02 11:12:16 +0100945 if ($action === 'crop')
Derek Allard2067d1a2008-11-13 22:59:24 +0000946 {
947 $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
948 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100949 elseif ($action === 'rotate')
Derek Allard2067d1a2008-11-13 22:59:24 +0000950 {
951 switch ($this->rotation_angle)
952 {
Andrey Andreev56454792012-05-17 14:32:19 +0300953 case 90: $angle = 'r270';
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300955 case 180: $angle = 'r180';
Derek Allard2067d1a2008-11-13 22:59:24 +0000956 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300957 case 270: $angle = 'r90';
Derek Allard2067d1a2008-11-13 22:59:24 +0000958 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300959 case 'vrt': $angle = 'tb';
Derek Allard2067d1a2008-11-13 22:59:24 +0000960 break;
Andrey Andreev56454792012-05-17 14:32:19 +0300961 case 'hor': $angle = 'lr';
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 break;
963 }
964
965 $cmd_inner = 'pnmflip -'.$angle.' ';
966 }
967 else // Resize
968 {
969 $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
970 }
971
972 $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
973
974 $retval = 1;
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200975 // exec() might be disabled
976 if (function_usable('exec'))
977 {
978 @exec($cmd, $output, $retval);
979 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000980
Andrey Andreev8e70b792012-01-12 20:19:24 +0200981 // Did it work?
Derek Allard2067d1a2008-11-13 22:59:24 +0000982 if ($retval > 0)
983 {
984 $this->set_error('imglib_image_process_failed');
985 return FALSE;
986 }
987
988 // With NetPBM we have to create a temporary image.
989 // If you try manipulating the original it fails so
990 // we have to rename the temp file.
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200991 copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
Andrey Andreev2c8baeb2012-01-19 15:45:28 +0200992 unlink($this->dest_folder.'netpbm.tmp');
Andrey Andreev45965742014-08-27 20:40:11 +0300993 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +0000994
995 return TRUE;
996 }
997
998 // --------------------------------------------------------------------
999
1000 /**
1001 * Image Rotate Using GD
1002 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001003 * @return bool
1004 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001005 public function image_rotate_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001006 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001007 // Create the image handle
Derek Allard2067d1a2008-11-13 22:59:24 +00001008 if ( ! ($src_img = $this->image_create_gd()))
1009 {
1010 return FALSE;
1011 }
1012
1013 // Set the background color
1014 // This won't work with transparent PNG files so we are
1015 // going to have to figure out how to determine the color
1016 // of the alpha channel in a future release.
1017
Andrey Andreev3a197592015-05-21 01:05:06 +03001018 $white = imagecolorallocate($src_img, 255, 255, 255);
Derek Allard2067d1a2008-11-13 22:59:24 +00001019
Andrey Andreev8e70b792012-01-12 20:19:24 +02001020 // Rotate it!
Derek Allard2067d1a2008-11-13 22:59:24 +00001021 $dst_img = imagerotate($src_img, $this->rotation_angle, $white);
1022
Andrey Andreev8e70b792012-01-12 20:19:24 +02001023 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001024 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001025 {
1026 $this->image_display_gd($dst_img);
1027 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001028 elseif ( ! $this->image_save_gd($dst_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001030 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001031 }
1032
Andrey Andreev8e70b792012-01-12 20:19:24 +02001033 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001034 imagedestroy($dst_img);
1035 imagedestroy($src_img);
1036
Andrey Andreev45965742014-08-27 20:40:11 +03001037 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001038
Pascal Kriete8761ef52011-02-14 13:13:52 -05001039 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001040 }
1041
1042 // --------------------------------------------------------------------
1043
1044 /**
1045 * Create Mirror Image using GD
1046 *
1047 * This function will flip horizontal or vertical
1048 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001049 * @return bool
1050 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001051 public function image_mirror_gd()
Derek Allard2067d1a2008-11-13 22:59:24 +00001052 {
1053 if ( ! $src_img = $this->image_create_gd())
1054 {
1055 return FALSE;
1056 }
1057
Derek Jones4b9c6292011-07-01 17:40:48 -05001058 $width = $this->orig_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001059 $height = $this->orig_height;
1060
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001061 if ($this->rotation_angle === 'hor')
Derek Allard2067d1a2008-11-13 22:59:24 +00001062 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001063 for ($i = 0; $i < $height; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001064 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001065 $left = 0;
1066 $right = $width - 1;
1067
Derek Allard2067d1a2008-11-13 22:59:24 +00001068 while ($left < $right)
1069 {
1070 $cl = imagecolorat($src_img, $left, $i);
1071 $cr = imagecolorat($src_img, $right, $i);
1072
1073 imagesetpixel($src_img, $left, $i, $cr);
1074 imagesetpixel($src_img, $right, $i, $cl);
1075
1076 $left++;
1077 $right--;
1078 }
1079 }
1080 }
1081 else
1082 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001083 for ($i = 0; $i < $width; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 {
Andrey Andreevfbde2792015-05-11 11:03:06 +03001085 $top = 0;
1086 $bottom = $height - 1;
1087
Andrey Andreev5d78fd82015-05-11 18:19:01 +03001088 while ($top < $bottom)
Derek Allard2067d1a2008-11-13 22:59:24 +00001089 {
1090 $ct = imagecolorat($src_img, $i, $top);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001091 $cb = imagecolorat($src_img, $i, $bottom);
Derek Allard2067d1a2008-11-13 22:59:24 +00001092
1093 imagesetpixel($src_img, $i, $top, $cb);
Andrey Andreevfbde2792015-05-11 11:03:06 +03001094 imagesetpixel($src_img, $i, $bottom, $ct);
Derek Allard2067d1a2008-11-13 22:59:24 +00001095
1096 $top++;
Andrey Andreevfbde2792015-05-11 11:03:06 +03001097 $bottom--;
Derek Allard2067d1a2008-11-13 22:59:24 +00001098 }
1099 }
1100 }
1101
Andrey Andreev8e70b792012-01-12 20:19:24 +02001102 // Show the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001103 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001104 {
1105 $this->image_display_gd($src_img);
1106 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001107 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001108 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001109 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001110 }
1111
Andrey Andreev8e70b792012-01-12 20:19:24 +02001112 // Kill the file handles
Derek Allard2067d1a2008-11-13 22:59:24 +00001113 imagedestroy($src_img);
1114
Andrey Andreev45965742014-08-27 20:40:11 +03001115 chmod($this->full_dst_path, $this->file_permissions);
Derek Allard2067d1a2008-11-13 22:59:24 +00001116
1117 return TRUE;
1118 }
1119
1120 // --------------------------------------------------------------------
1121
1122 /**
1123 * Image Watermark
1124 *
1125 * This is a wrapper function that chooses the type
1126 * of watermarking based on the specified preference.
1127 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001128 * @return bool
1129 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001130 public function watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001131 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001132 return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark();
Derek Allard2067d1a2008-11-13 22:59:24 +00001133 }
1134
1135 // --------------------------------------------------------------------
1136
1137 /**
1138 * Watermark - Graphic Version
1139 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001140 * @return bool
1141 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001142 public function overlay_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001143 {
1144 if ( ! function_exists('imagecolortransparent'))
1145 {
1146 $this->set_error('imglib_gd_required');
1147 return FALSE;
1148 }
1149
Andrey Andreev8e70b792012-01-12 20:19:24 +02001150 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001151 $this->get_image_properties();
1152
Andrey Andreev8e70b792012-01-12 20:19:24 +02001153 // Fetch watermark image properties
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001154 $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001155 $wm_img_type = $props['image_type'];
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001156 $wm_width = $props['width'];
1157 $wm_height = $props['height'];
Derek Allard2067d1a2008-11-13 22:59:24 +00001158
Andrey Andreev8e70b792012-01-12 20:19:24 +02001159 // Create two image resources
Derek Jones4b9c6292011-07-01 17:40:48 -05001160 $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001161 $src_img = $this->image_create_gd($this->full_src_path);
1162
1163 // Reverse the offset if necessary
1164 // When the image is positioned at the bottom
1165 // we don't want the vertical offset to push it
Andrey Andreev8e70b792012-01-12 20:19:24 +02001166 // further down. We want the reverse, so we'll
1167 // invert the offset. Same with the horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001168 // offset when the image is at the right
1169
Andrey Andreev8e70b792012-01-12 20:19:24 +02001170 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1171 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001172
Alex Bilbied261b1e2012-06-02 11:12:16 +01001173 if ($this->wm_vrt_alignment === 'B')
Derek Allard2067d1a2008-11-13 22:59:24 +00001174 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
1175
Alex Bilbied261b1e2012-06-02 11:12:16 +01001176 if ($this->wm_hor_alignment === 'R')
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 $this->wm_hor_offset = $this->wm_hor_offset * -1;
1178
Andrey Andreev8e70b792012-01-12 20:19:24 +02001179 // Set the base x and y axis values
Derek Allard2067d1a2008-11-13 22:59:24 +00001180 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1181 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1182
Andrey Andreev8e70b792012-01-12 20:19:24 +02001183 // Set the vertical position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001184 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001185 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001186 $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
1187 }
1188 elseif ($this->wm_vrt_alignment === 'B')
1189 {
1190 $y_axis += $this->orig_height - $wm_height;
Derek Allard2067d1a2008-11-13 22:59:24 +00001191 }
1192
Andrey Andreev8e70b792012-01-12 20:19:24 +02001193 // Set the horizontal position
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001194 if ($this->wm_hor_alignment === 'C')
Derek Allard2067d1a2008-11-13 22:59:24 +00001195 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001196 $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
1197 }
1198 elseif ($this->wm_hor_alignment === 'R')
1199 {
1200 $x_axis += $this->orig_width - $wm_width;
Derek Allard2067d1a2008-11-13 22:59:24 +00001201 }
1202
Andrey Andreev10fb7d12015-08-03 10:05:29 +03001203 // Build the finalized image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001204 if ($wm_img_type === 3 && function_exists('imagealphablending'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001205 {
1206 @imagealphablending($src_img, TRUE);
Barry Mienydd671972010-10-04 16:33:58 +02001207 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001208
1209 // Set RGB values for text and shadow
1210 $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
1211 $alpha = ($rgba & 0x7F000000) >> 24;
1212
1213 // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency
1214 if ($alpha > 0)
1215 {
1216 // copy the image directly, the image's alpha transparency being the sole determinant of blending
1217 imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
1218 }
1219 else
1220 {
1221 // set our RGB value from above to be transparent and merge the images with the specified opacity
1222 imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp));
1223 imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
1224 }
1225
Andrey Andreevdb037db2015-01-12 13:45:12 +02001226 // We can preserve transparency for PNG images
Дмитрийb23b8fc2014-10-20 00:36:55 +04001227 if ($this->image_type === 3)
1228 {
1229 imagealphablending($src_img, FALSE);
1230 imagesavealpha($src_img, TRUE);
1231 }
1232
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001233 // Output the image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001234 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001235 {
1236 $this->image_display_gd($src_img);
1237 }
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001238 elseif ( ! $this->image_save_gd($src_img)) // ... or save it
Derek Allard2067d1a2008-11-13 22:59:24 +00001239 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001240 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001241 }
1242
1243 imagedestroy($src_img);
1244 imagedestroy($wm_img);
1245
1246 return TRUE;
1247 }
1248
1249 // --------------------------------------------------------------------
1250
1251 /**
1252 * Watermark - Text Version
1253 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001254 * @return bool
1255 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001256 public function text_watermark()
Derek Allard2067d1a2008-11-13 22:59:24 +00001257 {
1258 if ( ! ($src_img = $this->image_create_gd()))
1259 {
1260 return FALSE;
1261 }
1262
Alex Bilbied261b1e2012-06-02 11:12:16 +01001263 if ($this->wm_use_truetype === TRUE && ! file_exists($this->wm_font_path))
Derek Allard2067d1a2008-11-13 22:59:24 +00001264 {
1265 $this->set_error('imglib_missing_font');
1266 return FALSE;
1267 }
1268
Andrey Andreev8e70b792012-01-12 20:19:24 +02001269 // Fetch source image properties
Derek Allard2067d1a2008-11-13 22:59:24 +00001270 $this->get_image_properties();
1271
Derek Allard2067d1a2008-11-13 22:59:24 +00001272 // Reverse the vertical offset
1273 // When the image is positioned at the bottom
1274 // we don't want the vertical offset to push it
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001275 // further down. We want the reverse, so we'll
Andrey Andreev8e70b792012-01-12 20:19:24 +02001276 // invert the offset. Note: The horizontal
Derek Allard2067d1a2008-11-13 22:59:24 +00001277 // offset flips itself automatically
1278
Alex Bilbied261b1e2012-06-02 11:12:16 +01001279 if ($this->wm_vrt_alignment === 'B')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001280 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001281 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001282 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001283
Alex Bilbied261b1e2012-06-02 11:12:16 +01001284 if ($this->wm_hor_alignment === 'R')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001285 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001286 $this->wm_hor_offset = $this->wm_hor_offset * -1;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001287 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001288
1289 // Set font width and height
1290 // These are calculated differently depending on
1291 // whether we are using the true type font or not
Alex Bilbied261b1e2012-06-02 11:12:16 +01001292 if ($this->wm_use_truetype === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001293 {
Andrey Andreeve52fc262014-02-11 13:27:01 +02001294 if (empty($this->wm_font_size))
Andrey Andreeva92b9032011-12-24 19:05:58 +02001295 {
1296 $this->wm_font_size = 17;
1297 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001298
Andrey Andreeve52fc262014-02-11 13:27:01 +02001299 if (function_exists('imagettfbbox'))
1300 {
1301 $temp = imagettfbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text);
1302 $temp = $temp[2] - $temp[0];
1303
1304 $fontwidth = $temp / strlen($this->wm_text);
1305 }
1306 else
1307 {
1308 $fontwidth = $this->wm_font_size - ($this->wm_font_size / 4);
1309 }
1310
Derek Allard2067d1a2008-11-13 22:59:24 +00001311 $fontheight = $this->wm_font_size;
1312 $this->wm_vrt_offset += $this->wm_font_size;
1313 }
1314 else
1315 {
Derek Jones4b9c6292011-07-01 17:40:48 -05001316 $fontwidth = imagefontwidth($this->wm_font_size);
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 $fontheight = imagefontheight($this->wm_font_size);
1318 }
1319
1320 // Set base X and Y axis values
1321 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1322 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1323
Alex Bilbied261b1e2012-06-02 11:12:16 +01001324 if ($this->wm_use_drop_shadow === FALSE)
omar0779e992015-01-31 11:57:07 -07001325 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001326 $this->wm_shadow_distance = 0;
omar0779e992015-01-31 11:57:07 -07001327 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001328
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001329 $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]);
1330 $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001331
omar0779e992015-01-31 11:57:07 -07001332 // Set vertical alignment
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001333 if ($this->wm_vrt_alignment === 'M')
Derek Allard2067d1a2008-11-13 22:59:24 +00001334 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001335 $y_axis += ($this->orig_height / 2) + ($fontheight / 2);
1336 }
1337 elseif ($this->wm_vrt_alignment === 'B')
1338 {
1339 $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2);
Derek Allard2067d1a2008-11-13 22:59:24 +00001340 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001341
omar0779e992015-01-31 11:57:07 -07001342 // Set horizontal alignment
1343 if ($this->wm_hor_alignment === 'R')
1344 {
omar9c855322015-01-31 11:58:03 -07001345 $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)) - $this->wm_shadow_distance;
omar0779e992015-01-31 11:57:07 -07001346 }
1347 elseif ($this->wm_hor_alignment === 'C')
1348 {
1349 $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2);
1350 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001351
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001352 if ($this->wm_use_drop_shadow)
Derek Allard2067d1a2008-11-13 22:59:24 +00001353 {
omar0779e992015-01-31 11:57:07 -07001354 // Offset from text
1355 $x_shad = $x_axis + $this->wm_shadow_distance;
1356 $y_shad = $y_axis + $this->wm_shadow_distance;
Andrey Andreev3a197592015-05-21 01:05:06 +03001357
omar0779e992015-01-31 11:57:07 -07001358 /* Set RGB values for shadow
Andrey Andreev8323ae62011-12-31 18:39:10 +02001359 *
1360 * First character is #, so we don't really need it.
1361 * Get the rest of the string and split it into 2-length
1362 * hex values:
1363 */
Andrey Andreev8323ae62011-12-31 18:39:10 +02001364 $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2);
Ronald Beilsma8f80bc42012-01-12 16:41:49 +01001365 $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2]));
Andrey Andreev3a197592015-05-21 01:05:06 +03001366
omar0779e992015-01-31 11:57:07 -07001367 // Add the shadow to the source image
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001368 if ($this->wm_use_truetype)
1369 {
1370 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 +02001371 }
1372 else
1373 {
1374 imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
Andrey Andreev64dbdfb2011-12-30 14:14:07 +02001375 }
omar0779e992015-01-31 11:57:07 -07001376 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001377
omar0779e992015-01-31 11:57:07 -07001378 /* Set RGB values for text
1379 *
1380 * First character is #, so we don't really need it.
1381 * Get the rest of the string and split it into 2-length
1382 * hex values:
1383 */
1384 $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2);
1385 $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2]));
Andrey Andreev99ae2262012-10-05 15:14:30 +03001386
omar0779e992015-01-31 11:57:07 -07001387 // Add the text to the source image
1388 if ($this->wm_use_truetype)
1389 {
1390 imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text);
1391 }
1392 else
1393 {
1394 imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
1395 }
Andrey Andreev3a197592015-05-21 01:05:06 +03001396
omar0779e992015-01-31 11:57:07 -07001397 // We can preserve transparency for PNG images
1398 if ($this->image_type === 3)
1399 {
1400 imagealphablending($src_img, FALSE);
1401 imagesavealpha($src_img, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +00001402 }
1403
Andrey Andreev8e70b792012-01-12 20:19:24 +02001404 // Output the final image
Alex Bilbied261b1e2012-06-02 11:12:16 +01001405 if ($this->dynamic_output === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001406 {
1407 $this->image_display_gd($src_img);
1408 }
1409 else
1410 {
1411 $this->image_save_gd($src_img);
1412 }
1413
1414 imagedestroy($src_img);
1415
1416 return TRUE;
1417 }
1418
1419 // --------------------------------------------------------------------
1420
1421 /**
1422 * Create Image - GD
1423 *
1424 * This simply creates an image resource handle
1425 * based on the type of image being processed
1426 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001427 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001428 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001429 * @return resource
1430 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001431 public function image_create_gd($path = '', $image_type = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001432 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001433 if ($path === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001434 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001435 $path = $this->full_src_path;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001436 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001437
Alex Bilbied261b1e2012-06-02 11:12:16 +01001438 if ($image_type === '')
Andrey Andreeve52fc262014-02-11 13:27:01 +02001439 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001440 $image_type = $this->image_type;
Andrey Andreeve52fc262014-02-11 13:27:01 +02001441 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001442
Derek Allard2067d1a2008-11-13 22:59:24 +00001443 switch ($image_type)
1444 {
Andrey Andreev3a197592015-05-21 01:05:06 +03001445 case 1:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001446 if ( ! function_exists('imagecreatefromgif'))
1447 {
1448 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1449 return FALSE;
1450 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001451
Andrey Andreeve52fc262014-02-11 13:27:01 +02001452 return imagecreatefromgif($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001453 case 2:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001454 if ( ! function_exists('imagecreatefromjpeg'))
1455 {
1456 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1457 return FALSE;
1458 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001459
Andrey Andreeve52fc262014-02-11 13:27:01 +02001460 return imagecreatefromjpeg($path);
Andrey Andreev3a197592015-05-21 01:05:06 +03001461 case 3:
Andrey Andreeve52fc262014-02-11 13:27:01 +02001462 if ( ! function_exists('imagecreatefrompng'))
1463 {
1464 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1465 return FALSE;
1466 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001467
Andrey Andreeve52fc262014-02-11 13:27:01 +02001468 return imagecreatefrompng($path);
1469 default:
1470 $this->set_error(array('imglib_unsupported_imagecreate'));
1471 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001472 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001473 }
1474
1475 // --------------------------------------------------------------------
1476
1477 /**
1478 * Write image file to disk - GD
1479 *
1480 * Takes an image resource as input and writes the file
1481 * to the specified destination
1482 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001483 * @param resource
1484 * @return bool
1485 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001486 public function image_save_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001487 {
1488 switch ($this->image_type)
1489 {
Andrey Andreev56454792012-05-17 14:32:19 +03001490 case 1:
1491 if ( ! function_exists('imagegif'))
1492 {
1493 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1494 return FALSE;
1495 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001496
Andrey Andreev56454792012-05-17 14:32:19 +03001497 if ( ! @imagegif($resource, $this->full_dst_path))
1498 {
1499 $this->set_error('imglib_save_failed');
1500 return FALSE;
1501 }
1502 break;
1503 case 2:
1504 if ( ! function_exists('imagejpeg'))
1505 {
1506 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1507 return FALSE;
1508 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001509
Andrey Andreev56454792012-05-17 14:32:19 +03001510 if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
1511 {
1512 $this->set_error('imglib_save_failed');
1513 return FALSE;
1514 }
1515 break;
1516 case 3:
1517 if ( ! function_exists('imagepng'))
1518 {
1519 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1520 return FALSE;
1521 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001522
Andrey Andreev56454792012-05-17 14:32:19 +03001523 if ( ! @imagepng($resource, $this->full_dst_path))
1524 {
1525 $this->set_error('imglib_save_failed');
1526 return FALSE;
1527 }
1528 break;
1529 default:
1530 $this->set_error(array('imglib_unsupported_imagecreate'));
1531 return FALSE;
1532 break;
Derek Allard2067d1a2008-11-13 22:59:24 +00001533 }
1534
1535 return TRUE;
1536 }
1537
1538 // --------------------------------------------------------------------
1539
1540 /**
1541 * Dynamically outputs an image
1542 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001543 * @param resource
1544 * @return void
1545 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001546 public function image_display_gd($resource)
Derek Allard2067d1a2008-11-13 22:59:24 +00001547 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001548 header('Content-Disposition: filename='.$this->source_image.';');
1549 header('Content-Type: '.$this->mime_type);
Derek Allard2067d1a2008-11-13 22:59:24 +00001550 header('Content-Transfer-Encoding: binary');
1551 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
1552
1553 switch ($this->image_type)
1554 {
Andrey Andreev56454792012-05-17 14:32:19 +03001555 case 1 : imagegif($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001556 break;
Ted Wood9cc707b2013-01-08 19:41:45 -08001557 case 2 : imagejpeg($resource, NULL, $this->quality);
Derek Allard2067d1a2008-11-13 22:59:24 +00001558 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001559 case 3 : imagepng($resource);
Derek Allard2067d1a2008-11-13 22:59:24 +00001560 break;
Andrey Andreev56454792012-05-17 14:32:19 +03001561 default: echo 'Unable to display the image';
Derek Allard2067d1a2008-11-13 22:59:24 +00001562 break;
1563 }
1564 }
1565
1566 // --------------------------------------------------------------------
1567
1568 /**
1569 * Re-proportion Image Width/Height
1570 *
1571 * When creating thumbs, the desired width/height
1572 * can end up warping the image due to an incorrect
1573 * ratio between the full-sized image and the thumb.
1574 *
1575 * This function lets us re-proportion the width/height
1576 * if users choose to maintain the aspect ratio when resizing.
1577 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001578 * @return void
1579 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001580 public function image_reproportion()
Derek Allard2067d1a2008-11-13 22:59:24 +00001581 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001582 if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001583 OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height))
1584 OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height))
Derek Allard2067d1a2008-11-13 22:59:24 +00001585 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001586 return;
Derek Allard2067d1a2008-11-13 22:59:24 +00001587 }
1588
Andrey Andreev7a7ad782012-11-12 17:21:01 +02001589 // Sanitize
Andrey Andreev8e70b792012-01-12 20:19:24 +02001590 $this->width = (int) $this->width;
1591 $this->height = (int) $this->height;
1592
1593 if ($this->master_dim !== 'width' && $this->master_dim !== 'height')
Derek Allard2067d1a2008-11-13 22:59:24 +00001594 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001595 if ($this->width > 0 && $this->height > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001596 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001597 $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0)
1598 ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001599 }
1600 else
1601 {
Andrey Andreev8e70b792012-01-12 20:19:24 +02001602 $this->master_dim = ($this->height === 0) ? 'width' : 'height';
Derek Allard2067d1a2008-11-13 22:59:24 +00001603 }
1604 }
Andrey Andreev8e70b792012-01-12 20:19:24 +02001605 elseif (($this->master_dim === 'width' && $this->width === 0)
1606 OR ($this->master_dim === 'height' && $this->height === 0))
1607 {
1608 return;
1609 }
1610
1611 if ($this->master_dim === 'width')
1612 {
1613 $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width);
1614 }
1615 else
1616 {
1617 $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height);
1618 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001619 }
1620
1621 // --------------------------------------------------------------------
1622
1623 /**
1624 * Get image properties
1625 *
1626 * A helper function that gets info about the file
1627 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001628 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001629 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001630 * @return mixed
1631 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001632 public function get_image_properties($path = '', $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001633 {
1634 // For now we require GD but we should
1635 // find a way to determine this using IM or NetPBM
1636
Alex Bilbied261b1e2012-06-02 11:12:16 +01001637 if ($path === '')
Andrey Andreev8e70b792012-01-12 20:19:24 +02001638 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001639 $path = $this->full_src_path;
Andrey Andreev8e70b792012-01-12 20:19:24 +02001640 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001641
1642 if ( ! file_exists($path))
1643 {
1644 $this->set_error('imglib_invalid_path');
1645 return FALSE;
1646 }
1647
Phil Sturgeon901998a2011-08-26 10:03:33 +01001648 $vals = getimagesize($path);
Derek Allard2067d1a2008-11-13 22:59:24 +00001649 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
Andrey Andreeva92b9032011-12-24 19:05:58 +02001650 $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001651
Alex Bilbied261b1e2012-06-02 11:12:16 +01001652 if ($return === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001653 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001654 return array(
1655 'width' => $vals[0],
1656 'height' => $vals[1],
1657 'image_type' => $vals[2],
1658 'size_str' => $vals[3],
1659 'mime_type' => $mime
1660 );
Derek Allard2067d1a2008-11-13 22:59:24 +00001661 }
1662
Andrey Andreeva92b9032011-12-24 19:05:58 +02001663 $this->orig_width = $vals[0];
1664 $this->orig_height = $vals[1];
1665 $this->image_type = $vals[2];
1666 $this->size_str = $vals[3];
Derek Allard2067d1a2008-11-13 22:59:24 +00001667 $this->mime_type = $mime;
1668
1669 return TRUE;
1670 }
1671
1672 // --------------------------------------------------------------------
1673
1674 /**
1675 * Size calculator
1676 *
1677 * This function takes a known width x height and
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001678 * recalculates it to a new size. Only one
Derek Allard2067d1a2008-11-13 22:59:24 +00001679 * new variable needs to be known
1680 *
1681 * $props = array(
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001682 * 'width' => $width,
1683 * 'height' => $height,
1684 * 'new_width' => 40,
1685 * 'new_height' => ''
1686 * );
Derek Allard2067d1a2008-11-13 22:59:24 +00001687 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001688 * @param array
1689 * @return array
1690 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001691 public function size_calculator($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001692 {
1693 if ( ! is_array($vals))
1694 {
1695 return;
1696 }
1697
1698 $allowed = array('new_width', 'new_height', 'width', 'height');
1699
1700 foreach ($allowed as $item)
1701 {
Andrey Andreev56454792012-05-17 14:32:19 +03001702 if (empty($vals[$item]))
1703 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001704 $vals[$item] = 0;
Andrey Andreev56454792012-05-17 14:32:19 +03001705 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001706 }
1707
Alex Bilbied261b1e2012-06-02 11:12:16 +01001708 if ($vals['width'] === 0 OR $vals['height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001709 {
1710 return $vals;
1711 }
1712
Alex Bilbied261b1e2012-06-02 11:12:16 +01001713 if ($vals['new_width'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001714 {
1715 $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
1716 }
Alex Bilbied261b1e2012-06-02 11:12:16 +01001717 elseif ($vals['new_height'] === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001718 {
1719 $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
1720 }
1721
1722 return $vals;
1723 }
1724
1725 // --------------------------------------------------------------------
1726
1727 /**
1728 * Explode source_image
1729 *
1730 * This is a helper function that extracts the extension
Derek Jones4b9c6292011-07-01 17:40:48 -05001731 * from the source_image. This function lets us deal with
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001732 * source_images with multiple periods, like: my.cool.jpg
Derek Allard2067d1a2008-11-13 22:59:24 +00001733 * It returns an associative array with two elements:
Derek Jones4b9c6292011-07-01 17:40:48 -05001734 * $array['ext'] = '.jpg';
Derek Allard2067d1a2008-11-13 22:59:24 +00001735 * $array['name'] = 'my.cool';
1736 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001737 * @param array
1738 * @return array
1739 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001740 public function explode_name($source_image)
Derek Allard2067d1a2008-11-13 22:59:24 +00001741 {
Derek Jones08cae632009-02-10 20:03:29 +00001742 $ext = strrchr($source_image, '.');
1743 $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext));
Barry Mienydd671972010-10-04 16:33:58 +02001744
Derek Jones08cae632009-02-10 20:03:29 +00001745 return array('ext' => $ext, 'name' => $name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001746 }
1747
1748 // --------------------------------------------------------------------
1749
1750 /**
1751 * Is GD Installed?
1752 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001753 * @return bool
1754 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001755 public function gd_loaded()
Derek Allard2067d1a2008-11-13 22:59:24 +00001756 {
1757 if ( ! extension_loaded('gd'))
1758 {
Andrey Andreeva92b9032011-12-24 19:05:58 +02001759 /* As it is stated in the PHP manual, dl() is not always available
1760 * and even if so - it could generate an E_WARNING message on failure
1761 */
Andrey Andreev8e70b792012-01-12 20:19:24 +02001762 return (function_exists('dl') && @dl('gd.so'));
Derek Allard2067d1a2008-11-13 22:59:24 +00001763 }
1764
1765 return TRUE;
1766 }
1767
1768 // --------------------------------------------------------------------
1769
1770 /**
1771 * Get GD version
1772 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001773 * @return mixed
1774 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001775 public function gd_version()
Derek Allard2067d1a2008-11-13 22:59:24 +00001776 {
1777 if (function_exists('gd_info'))
1778 {
1779 $gd_version = @gd_info();
Andrey Andreev8e70b792012-01-12 20:19:24 +02001780 return preg_replace('/\D/', '', $gd_version['GD Version']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001781 }
1782
1783 return FALSE;
1784 }
1785
1786 // --------------------------------------------------------------------
1787
1788 /**
1789 * Set error message
1790 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001791 * @param string
1792 * @return void
1793 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001794 public function set_error($msg)
Derek Allard2067d1a2008-11-13 22:59:24 +00001795 {
1796 $CI =& get_instance();
1797 $CI->lang->load('imglib');
1798
1799 if (is_array($msg))
1800 {
1801 foreach ($msg as $val)
1802 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001803 $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001804 $this->error_msg[] = $msg;
1805 log_message('error', $msg);
1806 }
1807 }
1808 else
1809 {
Alex Bilbied261b1e2012-06-02 11:12:16 +01001810 $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg);
Derek Allard2067d1a2008-11-13 22:59:24 +00001811 $this->error_msg[] = $msg;
1812 log_message('error', $msg);
1813 }
1814 }
1815
1816 // --------------------------------------------------------------------
1817
1818 /**
1819 * Show error messages
1820 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001821 * @param string
Timothy Warrenb82bc3a2012-04-27 09:12:58 -04001822 * @param string
Derek Allard2067d1a2008-11-13 22:59:24 +00001823 * @return string
1824 */
Andrey Andreev4eea9892011-12-19 12:05:41 +02001825 public function display_errors($open = '<p>', $close = '</p>')
Derek Allard2067d1a2008-11-13 22:59:24 +00001826 {
Andrey Andreev2c8baeb2012-01-19 15:45:28 +02001827 return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : '';
Derek Allard2067d1a2008-11-13 22:59:24 +00001828 }
1829
1830}