blob: 8a686675383d7ebf387cd5219f06077669ba01e3 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allardc5d88792007-02-01 03:12:32 +00002/**
Derek Allardd2df9bc2007-04-15 17:41:17 +00003 * CodeIgniter
Derek Allardc5d88792007-02-01 03:12:32 +00004 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Rick Ellisd02b5bf2008-09-12 23:35:31 +00009 * @copyright Copyright (c) 2008, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardc5d88792007-02-01 03:12:32 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Image Manipulation class
20 *
21 * @package CodeIgniter
22 * @subpackage Libraries
23 * @category Image_lib
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/libraries/image_lib.html
Derek Allardc5d88792007-02-01 03:12:32 +000026 */
27class CI_Image_lib {
28
29 var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2
30 var $library_path = '';
31 var $dynamic_output = FALSE; // Whether to send to browser or write to disk
32 var $source_image = '';
33 var $new_image = '';
34 var $width = '';
35 var $height = '';
36 var $quality = '90';
37 var $create_thumb = FALSE;
38 var $thumb_marker = '_thumb';
39 var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values
40 var $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension
41 var $rotation_angle = '';
42 var $x_axis = '';
43 var $y_axis = '';
44
45 // Watermark Vars
46 var $wm_text = ''; // Watermark text if graphic is not used
47 var $wm_type = 'text'; // Type of watermarking. Options: text/overlay
48 var $wm_x_transp = 4;
49 var $wm_y_transp = 4;
50 var $wm_overlay_path = ''; // Watermark image path
51 var $wm_font_path = ''; // TT font
52 var $wm_font_size = 17; // Font size (different versions of GD will either use points or pixels)
53 var $wm_vrt_alignment = 'B'; // Vertical alignment: T M B
54 var $wm_hor_alignment = 'C'; // Horizontal alignment: L R C
55 var $wm_padding = 0; // Padding around text
56 var $wm_hor_offset = 0; // Lets you push text to the right
57 var $wm_vrt_offset = 0; // Lets you push text down
58 var $wm_font_color = '#ffffff'; // Text color
59 var $wm_shadow_color = ''; // Dropshadow color
60 var $wm_shadow_distance = 2; // Dropshadow distance
61 var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image
62
63 // Private Vars
64 var $source_folder = '';
65 var $dest_folder = '';
66 var $mime_type = '';
67 var $orig_width = '';
68 var $orig_height = '';
69 var $image_type = '';
70 var $size_str = '';
71 var $full_src_path = '';
72 var $full_dst_path = '';
73 var $create_fnc = 'imagecreatetruecolor';
74 var $copy_fnc = 'imagecopyresampled';
75 var $error_msg = array();
76 var $wm_use_drop_shadow = FALSE;
77 var $wm_use_truetype = FALSE;
78
79 /**
80 * Constructor
81 *
82 * @access public
83 * @param string
84 * @return void
85 */
86 function CI_Image_lib($props = array())
87 {
88 if (count($props) > 0)
89 {
90 $this->initialize($props);
91 }
92
93 log_message('debug', "Image Lib Class Initialized");
94 }
95
96 // --------------------------------------------------------------------
97
98 /**
99 * Initialize image properties
100 *
101 * Resets values in case this class is used in a loop
102 *
103 * @access public
104 * @return void
105 */
106 function clear()
107 {
108 $props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');
109
110 foreach ($props as $val)
111 {
112 $this->$val = '';
Derek Allard44dbc782008-01-29 20:38:55 +0000113 }
114
115 // special consideration for master_dim
116 $this->master_dim = 'auto';
Derek Allardc5d88792007-02-01 03:12:32 +0000117 }
118
119 // --------------------------------------------------------------------
120
121 /**
122 * initialize image preferences
123 *
124 * @access public
125 * @param array
126 * @return void
127 */
128 function initialize($props = array())
129 {
130 /*
131 * Convert array elements into class variables
132 */
133 if (count($props) > 0)
134 {
135 foreach ($props as $key => $val)
136 {
137 $this->$key = $val;
138 }
139 }
140
141 /*
142 * Is there a source image?
143 *
144 * If not, there's no reason to continue
145 *
146 */
147 if ($this->source_image == '')
148 {
149 $this->set_error('imglib_source_image_required');
150 return FALSE;
151 }
152
153 /*
154 * Is getimagesize() Available?
155 *
156 * We use it to determine the image properties (width/height).
157 * Note: We need to figure out how to determine image
158 * properties using ImageMagick and NetPBM
159 *
160 */
Derek Jones0b59f272008-05-13 04:22:33 +0000161 if ( ! function_exists('getimagesize'))
Derek Allardc5d88792007-02-01 03:12:32 +0000162 {
163 $this->set_error('imglib_gd_required_for_props');
164 return FALSE;
165 }
166
167 $this->image_library = strtolower($this->image_library);
168
169 /*
170 * Set the full server path
171 *
172 * The source image may or may not contain a path.
173 * Either way, we'll try use realpath to generate the
174 * full server path in order to more reliably read it.
175 *
176 */
177 if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE)
178 {
179 $full_source_path = str_replace("\\", "/", realpath($this->source_image));
180 }
181 else
182 {
183 $full_source_path = $this->source_image;
184 }
185
186 $x = explode('/', $full_source_path);
187 $this->source_image = end($x);
188 $this->source_folder = str_replace($this->source_image, '', $full_source_path);
189
190 // Set the Image Properties
Derek Jones0b59f272008-05-13 04:22:33 +0000191 if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
Derek Allardc5d88792007-02-01 03:12:32 +0000192 {
193 return FALSE;
194 }
195
196 /*
197 * Assign the "new" image name/path
198 *
199 * If the user has set a "new_image" name it means
200 * we are making a copy of the source image. If not
201 * it means we are altering the original. We'll
202 * set the destination filename and path accordingly.
203 *
204 */
205 if ($this->new_image == '')
206 {
207 $this->dest_image = $this->source_image;
208 $this->dest_folder = $this->source_folder;
209 }
210 else
211 {
212 if (strpos($this->new_image, '/') === FALSE)
213 {
214 $this->dest_folder = $this->source_folder;
215 $this->dest_image = $this->new_image;
216 }
217 else
218 {
219 if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE)
220 {
221 $full_dest_path = str_replace("\\", "/", realpath($this->new_image));
222 }
223 else
224 {
225 $full_dest_path = $this->new_image;
226 }
227
228 // Is there a file name?
Derek Jonesef406402008-05-16 04:14:36 +0000229 if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path))
Derek Allardc5d88792007-02-01 03:12:32 +0000230 {
231 $this->dest_folder = $full_dest_path.'/';
232 $this->dest_image = $this->source_image;
233 }
234 else
235 {
236 $x = explode('/', $full_dest_path);
237 $this->dest_image = end($x);
238 $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path);
239 }
240 }
241 }
242
243 /*
244 * Compile the finalized filenames/paths
245 *
246 * We'll create two master strings containing the
247 * full server path to the source image and the
248 * full server path to the destination image.
249 * We'll also split the destination image name
250 * so we can insert the thumbnail marker if needed.
251 *
252 */
253 if ($this->create_thumb === FALSE OR $this->thumb_marker == '')
254 {
255 $this->thumb_marker = '';
256 }
257
258 $xp = $this->explode_name($this->dest_image);
259
260 $filename = $xp['name'];
261 $file_ext = $xp['ext'];
262
263 $this->full_src_path = $this->source_folder.$this->source_image;
264 $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext;
265
266 /*
267 * Should we maintain image proportions?
268 *
269 * When creating thumbs or copies, the target width/height
270 * might not be in correct proportion with the source
271 * image's width/height. We'll recalculate it here.
272 *
273 */
274 if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != ''))
275 {
276 $this->image_reproportion();
277 }
278
279 /*
280 * Was a width and height specified?
281 *
282 * If the destination width/height was
283 * not submitted we will use the values
284 * from the actual file
285 *
286 */
287 if ($this->width == '')
288 $this->width = $this->orig_width;
289
290 if ($this->height == '')
291 $this->height = $this->orig_height;
292
293 // Set the quality
294 $this->quality = trim(str_replace("%", "", $this->quality));
295
296 if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality))
297 $this->quality = 90;
298
299 // Set the x/y coordinates
300 $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis;
301 $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis;
302
303 // Watermark-related Stuff...
304 if ($this->wm_font_color != '')
305 {
306 if (strlen($this->wm_font_color) == 6)
307 {
308 $this->wm_font_color = '#'.$this->wm_font_color;
309 }
310 }
311
312 if ($this->wm_shadow_color != '')
313 {
314 if (strlen($this->wm_shadow_color) == 6)
315 {
316 $this->wm_shadow_color = '#'.$this->wm_shadow_color;
317 }
318 }
319
320 if ($this->wm_overlay_path != '')
321 {
322 $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path));
323 }
324
325 if ($this->wm_shadow_color != '')
326 {
327 $this->wm_use_drop_shadow = TRUE;
328 }
329
330 if ($this->wm_font_path != '')
331 {
332 $this->wm_use_truetype = TRUE;
333 }
334
335 return TRUE;
336 }
337
338 // --------------------------------------------------------------------
339
340 /**
341 * Image Resize
342 *
343 * This is a wrapper function that chooses the proper
344 * resize function based on the protocol specified
345 *
346 * @access public
347 * @return bool
348 */
349 function resize()
350 {
351 $protocol = 'image_process_'.$this->image_library;
352
353 if (eregi("gd2$", $protocol))
354 {
355 $protocol = 'image_process_gd';
356 }
357
358 return $this->$protocol('resize');
359 }
360
361 // --------------------------------------------------------------------
362
363 /**
364 * Image Crop
365 *
366 * This is a wrapper function that chooses the proper
367 * cropping function based on the protocol specified
368 *
369 * @access public
370 * @return bool
371 */
372 function crop()
373 {
374 $protocol = 'image_process_'.$this->image_library;
375
376 if (eregi("gd2$", $protocol))
377 {
378 $protocol = 'image_process_gd';
379 }
380
381 return $this->$protocol('crop');
382 }
383
384 // --------------------------------------------------------------------
385
386 /**
387 * Image Rotate
388 *
389 * This is a wrapper function that chooses the proper
390 * rotation function based on the protocol specified
391 *
392 * @access public
393 * @return bool
394 */
395 function rotate()
396 {
397 // Allowed rotation values
398 $degs = array(90, 180, 270, 'vrt', 'hor');
399
400 if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs, TRUE))
401 {
402 $this->set_error('imglib_rotation_angle_required');
403 return FALSE;
404 }
405
406 // Reassign the width and height
407 if ($this->rotation_angle == 90 OR $this->rotation_angle == 270)
408 {
409 $this->width = $this->orig_height;
410 $this->height = $this->orig_width;
411 }
412 else
413 {
414 $this->width = $this->orig_width;
415 $this->height = $this->orig_height;
416 }
417
418
419 // Choose resizing function
420 if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm')
421 {
422 $protocol = 'image_process_'.$this->image_library;
423
424 return $this->$protocol('rotate');
425 }
426
427 if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt')
428 {
429 return $this->image_mirror_gd();
430 }
431 else
432 {
433 return $this->image_rotate_gd();
434 }
435 }
436
437 // --------------------------------------------------------------------
438
439 /**
440 * Image Process Using GD/GD2
441 *
442 * This function will resize or crop
443 *
444 * @access public
445 * @param string
446 * @return bool
447 */
448 function image_process_gd($action = 'resize')
449 {
450 $v2_override = FALSE;
Derek Allard1d3137b2008-01-29 18:44:07 +0000451
Rick Ellis457817d2008-10-17 05:10:56 +0000452 // If the target width/height match the source, AND if the new file name is not equal to the old file name
453 // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
454 if ($this->dynamic_output === FALSE)
455 {
456 if (($this->orig_width == $this->width AND $this->orig_height == $this->height) AND ($this->source_image != $this->new_image))
Derek Allardc5d88792007-02-01 03:12:32 +0000457 {
Rick Ellis457817d2008-10-17 05:10:56 +0000458 if ( ! @copy($this->full_src_path, $this->full_dst_path))
459 {
460 $this->set_error('imglib_copy_failed');
461 return FALSE;
462 }
463
464 @chmod($this->full_dst_path, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000465 return TRUE;
466 }
Rick Ellis457817d2008-10-17 05:10:56 +0000467 }
468
469 if ($action == 'crop')
470 {
Derek Allardc5d88792007-02-01 03:12:32 +0000471 // Reassign the source width/height if cropping
472 $this->orig_width = $this->width;
473 $this->orig_height = $this->height;
474
475 // GD 2.0 has a cropping bug so we'll test for it
476 if ($this->gd_version() !== FALSE)
477 {
478 $gd_version = str_replace('0', '', $this->gd_version());
479 $v2_override = ($gd_version == 2) ? TRUE : FALSE;
480 }
481 }
482 else
Rick Ellis457817d2008-10-17 05:10:56 +0000483 {
Derek Allardc5d88792007-02-01 03:12:32 +0000484 // If resizing the x/y axis must be zero
485 $this->x_axis = 0;
486 $this->y_axis = 0;
487 }
488
489 // Create the image handle
Derek Jones0b59f272008-05-13 04:22:33 +0000490 if ( ! ($src_img = $this->image_create_gd()))
Derek Allardc5d88792007-02-01 03:12:32 +0000491 {
492 return FALSE;
493 }
494
Derek Allard4acd41a2008-03-05 16:22:31 +0000495 // Create The Image
496 //
497 // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater"
498 // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment
499 // below should that ever prove inaccurate.
500 //
501 // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE)
502 if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
Derek Allardc5d88792007-02-01 03:12:32 +0000503 {
504 $create = 'imagecreatetruecolor';
505 $copy = 'imagecopyresampled';
506 }
507 else
508 {
509 $create = 'imagecreate';
510 $copy = 'imagecopyresized';
511 }
512
513 $dst_img = $create($this->width, $this->height);
514 $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
515
516 // Show the image
517 if ($this->dynamic_output == TRUE)
518 {
519 $this->image_display_gd($dst_img);
520 }
521 else
522 {
523 // Or save it
Derek Jones0b59f272008-05-13 04:22:33 +0000524 if ( ! $this->image_save_gd($dst_img))
Derek Allardc5d88792007-02-01 03:12:32 +0000525 {
526 return FALSE;
527 }
528 }
529
530 // Kill the file handles
531 imagedestroy($dst_img);
532 imagedestroy($src_img);
533
534 // Set the file to 777
Derek Jones3ad8efe2008-04-04 18:56:04 +0000535 @chmod($this->full_dst_path, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000536
537 return TRUE;
538 }
539
540 // --------------------------------------------------------------------
541
542 /**
543 * Image Process Using ImageMagick
544 *
545 * This function will resize, crop or rotate
546 *
547 * @access public
548 * @param string
549 * @return bool
550 */
551 function image_process_imagemagick($action = 'resize')
552 {
553 // Do we have a vaild library path?
554 if ($this->library_path == '')
555 {
556 $this->set_error('imglib_libpath_invalid');
557 return FALSE;
558 }
559
Derek Jones0b59f272008-05-13 04:22:33 +0000560 if ( ! eregi("convert$", $this->library_path))
Derek Allardc5d88792007-02-01 03:12:32 +0000561 {
Derek Jones0b59f272008-05-13 04:22:33 +0000562 if ( ! eregi("/$", $this->library_path)) $this->library_path .= "/";
Derek Allardc5d88792007-02-01 03:12:32 +0000563
564 $this->library_path .= 'convert';
565 }
566
567 // Execute the command
568 $cmd = $this->library_path." -quality ".$this->quality;
569
570 if ($action == 'crop')
571 {
572 $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
573 }
574 elseif ($action == 'rotate')
575 {
576 switch ($this->rotation_angle)
577 {
578 case 'hor' : $angle = '-flop';
579 break;
580 case 'vrt' : $angle = '-flip';
581 break;
582 default : $angle = '-rotate '.$this->rotation_angle;
583 break;
584 }
585
586 $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
587 }
588 else // Resize
589 {
590 $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1";
591 }
592
593 $retval = 1;
594
595 @exec($cmd, $output, $retval);
596
597 // Did it work?
598 if ($retval > 0)
599 {
600 $this->set_error('imglib_image_process_failed');
601 return FALSE;
602 }
603
604 // Set the file to 777
Derek Jones3ad8efe2008-04-04 18:56:04 +0000605 @chmod($this->full_dst_path, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000606
607 return TRUE;
608 }
609
610 // --------------------------------------------------------------------
611
612 /**
613 * Image Process Using NetPBM
614 *
615 * This function will resize, crop or rotate
616 *
617 * @access public
618 * @param string
619 * @return bool
620 */
621 function image_process_netpbm($action = 'resize')
622 {
623 if ($this->library_path == '')
624 {
625 $this->set_error('imglib_libpath_invalid');
626 return FALSE;
627 }
628
629 // Build the resizing command
630 switch ($this->image_type)
631 {
632 case 1 :
633 $cmd_in = 'giftopnm';
634 $cmd_out = 'ppmtogif';
635 break;
636 case 2 :
637 $cmd_in = 'jpegtopnm';
638 $cmd_out = 'ppmtojpeg';
639 break;
640 case 3 :
641 $cmd_in = 'pngtopnm';
642 $cmd_out = 'ppmtopng';
643 break;
644 }
645
646 if ($action == 'crop')
647 {
648 $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height;
649 }
650 elseif ($action == 'rotate')
651 {
652 switch ($this->rotation_angle)
653 {
654 case 90 : $angle = 'r270';
655 break;
656 case 180 : $angle = 'r180';
657 break;
658 case 270 : $angle = 'r90';
659 break;
660 case 'vrt' : $angle = 'tb';
661 break;
662 case 'hor' : $angle = 'lr';
663 break;
664 }
665
666 $cmd_inner = 'pnmflip -'.$angle.' ';
667 }
668 else // Resize
669 {
670 $cmd_inner = 'pnmscale -xysize '.$this->width.' '.$this->height;
671 }
672
673 $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp';
674
675 $retval = 1;
676
677 @exec($cmd, $output, $retval);
678
679 // Did it work?
680 if ($retval > 0)
681 {
682 $this->set_error('imglib_image_process_failed');
683 return FALSE;
684 }
685
686 // With NetPBM we have to create a temporary image.
687 // If you try manipulating the original it fails so
688 // we have to rename the temp file.
689 copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path);
690 unlink ($this->dest_folder.'netpbm.tmp');
Derek Jones3ad8efe2008-04-04 18:56:04 +0000691 @chmod($dst_image, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000692
693 return TRUE;
694 }
695
696 // --------------------------------------------------------------------
697
698 /**
699 * Image Rotate Using GD
700 *
701 * @access public
702 * @return bool
703 */
704 function image_rotate_gd()
705 {
706 // Is Image Rotation Supported?
707 // this function is only supported as of PHP 4.3
Derek Jones0b59f272008-05-13 04:22:33 +0000708 if ( ! function_exists('imagerotate'))
Derek Allardc5d88792007-02-01 03:12:32 +0000709 {
710 $this->set_error('imglib_rotate_unsupported');
711 return FALSE;
712 }
713
714 // Create the image handle
Derek Jones0b59f272008-05-13 04:22:33 +0000715 if ( ! ($src_img = $this->image_create_gd()))
Derek Allardc5d88792007-02-01 03:12:32 +0000716 {
717 return FALSE;
718 }
719
720 // Set the background color
721 // This won't work with transparent PNG files so we are
722 // going to have to figure out how to determine the color
723 // of the alpha channel in a future release.
724
725 $white = imagecolorallocate($src_img, 255, 255, 255);
726
727 // Rotate it!
728 $dst_img = imagerotate($src_img, $this->rotation_angle, $white);
729
730 // Save the Image
731 if ($this->dynamic_output == TRUE)
732 {
733 $this->image_display_gd($dst_img);
734 }
735 else
736 {
737 // Or save it
Derek Jones0b59f272008-05-13 04:22:33 +0000738 if ( ! $this->image_save_gd($dst_img))
Derek Allardc5d88792007-02-01 03:12:32 +0000739 {
740 return FALSE;
741 }
742 }
743
744 // Kill the file handles
745 imagedestroy($dst_img);
746 imagedestroy($src_img);
747
748 // Set the file to 777
749
Derek Jones3ad8efe2008-04-04 18:56:04 +0000750 @chmod($this->full_dst_path, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000751
752 return true;
753 }
754
755 // --------------------------------------------------------------------
756
757 /**
758 * Create Mirror Image using GD
759 *
760 * This function will flip horizontal or vertical
761 *
762 * @access public
763 * @return bool
764 */
765 function image_mirror_gd()
766 {
Derek Jones0b59f272008-05-13 04:22:33 +0000767 if ( ! $src_img = $this->image_create_gd())
Derek Allardc5d88792007-02-01 03:12:32 +0000768 {
769 return FALSE;
770 }
771
772 $width = $this->orig_width;
773 $height = $this->orig_height;
774
775 if ($this->rotation_angle == 'hor')
776 {
777 for ($i = 0; $i < $height; $i++)
778 {
779 $left = 0;
780 $right = $width-1;
781
782 while ($left < $right)
783 {
784 $cl = imagecolorat($src_img, $left, $i);
785 $cr = imagecolorat($src_img, $right, $i);
786
787 imagesetpixel($src_img, $left, $i, $cr);
788 imagesetpixel($src_img, $right, $i, $cl);
789
790 $left++;
791 $right--;
792 }
793 }
794 }
795 else
796 {
797 for ($i = 0; $i < $width; $i++)
798 {
799 $top = 0;
800 $bot = $height-1;
801
802 while ($top < $bot)
803 {
804 $ct = imagecolorat($src_img, $i, $top);
805 $cb = imagecolorat($src_img, $i, $bot);
806
807 imagesetpixel($src_img, $i, $top, $cb);
808 imagesetpixel($src_img, $i, $bot, $ct);
809
810 $top++;
811 $bot--;
812 }
813 }
814 }
815
816 // Show the image
817 if ($this->dynamic_output == TRUE)
818 {
819 $this->image_display_gd($src_img);
820 }
821 else
822 {
823 // Or save it
Derek Jones0b59f272008-05-13 04:22:33 +0000824 if ( ! $this->image_save_gd($src_img))
Derek Allardc5d88792007-02-01 03:12:32 +0000825 {
826 return FALSE;
827 }
828 }
829
830 // Kill the file handles
831 imagedestroy($src_img);
832
833 // Set the file to 777
Derek Jones3ad8efe2008-04-04 18:56:04 +0000834 @chmod($this->full_dst_path, DIR_WRITE_MODE);
Derek Allardc5d88792007-02-01 03:12:32 +0000835
836 return TRUE;
837 }
838
839 // --------------------------------------------------------------------
840
841 /**
842 * Image Watermark
843 *
844 * This is a wrapper function that chooses the type
845 * of watermarking based on the specified preference.
846 *
847 * @access public
848 * @param string
849 * @return bool
850 */
851 function watermark()
852 {
853 if ($this->wm_type == 'overlay')
854 {
855 return $this->overlay_watermark();
856 }
857 else
858 {
859 return $this->text_watermark();
860 }
861 }
862
863 // --------------------------------------------------------------------
864
865 /**
866 * Watermark - Graphic Version
867 *
868 * @access public
869 * @return bool
870 */
871 function overlay_watermark()
872 {
Derek Jones0b59f272008-05-13 04:22:33 +0000873 if ( ! function_exists('imagecolortransparent'))
Derek Allardc5d88792007-02-01 03:12:32 +0000874 {
875 $this->set_error('imglib_gd_required');
876 return FALSE;
877 }
878
879 // Fetch source image properties
880 $this->get_image_properties();
881
882 // Fetch watermark image properties
883 $props = $this->get_image_properties($this->wm_overlay_path, TRUE);
884 $wm_img_type = $props['image_type'];
885 $wm_width = $props['width'];
886 $wm_height = $props['height'];
887
888 // Create two image resources
889 $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type);
890 $src_img = $this->image_create_gd($this->full_src_path);
891
892 // Reverse the offset if necessary
893 // When the image is positioned at the bottom
894 // we don't want the vertical offset to push it
895 // further down. We want the reverse, so we'll
896 // invert the offset. Same with the horizontal
897 // offset when the image is at the right
898
899 $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
900 $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
901
902 if ($this->wm_vrt_alignment == 'B')
903 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
904
905 if ($this->wm_hor_alignment == 'R')
906 $this->wm_hor_offset = $this->wm_hor_offset * -1;
907
908 // Set the base x and y axis values
909 $x_axis = $this->wm_hor_offset + $this->wm_padding;
910 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
911
912 // Set the vertical position
913 switch ($this->wm_vrt_alignment)
914 {
915 case 'T':
916 break;
917 case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2);
918 break;
919 case 'B': $y_axis += $this->orig_height - $wm_height;
920 break;
921 }
922
923 // Set the horizontal position
924 switch ($this->wm_hor_alignment)
925 {
926 case 'L':
927 break;
928 case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2);
929 break;
930 case 'R': $x_axis += $this->orig_width - $wm_width;
931 break;
932 }
933
934 // Build the finalized image
935 if ($wm_img_type == 3 AND function_exists('imagealphablending'))
936 {
937 @imagealphablending($src_img, TRUE);
938 }
Rick Ellisb5c93ce2008-10-01 01:21:54 +0000939
Derek Jones500fa6c2008-05-12 15:08:35 +0000940 // Set RGB values for text and shadow
941 $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
942 $alpha = ($rgba & 0x7F000000) >> 24;
943
944 // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency
945 if ($alpha > 0)
946 {
947 // copy the image directly, the image's alpha transparency being the sole determinant of blending
948 imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height);
949 }
950 else
951 {
952 // set our RGB value from above to be transparent and merge the images with the specified opacity
953 imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp));
954 imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity);
955 }
Derek Allardc5d88792007-02-01 03:12:32 +0000956
957 // Output the image
958 if ($this->dynamic_output == TRUE)
959 {
960 $this->image_display_gd($src_img);
961 }
962 else
963 {
Derek Jones0b59f272008-05-13 04:22:33 +0000964 if ( ! $this->image_save_gd($src_img))
Derek Allardc5d88792007-02-01 03:12:32 +0000965 {
966 return FALSE;
967 }
968 }
969
970 imagedestroy($src_img);
971 imagedestroy($wm_img);
972
973 return TRUE;
974 }
975
976 // --------------------------------------------------------------------
977
978 /**
979 * Watermark - Text Version
980 *
981 * @access public
982 * @return bool
983 */
984 function text_watermark()
985 {
Derek Jones0b59f272008-05-13 04:22:33 +0000986 if ( ! ($src_img = $this->image_create_gd()))
Derek Allardc5d88792007-02-01 03:12:32 +0000987 {
988 return FALSE;
989 }
990
991 if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path))
992 {
993 $this->set_error('imglib_missing_font');
994 return FALSE;
995 }
996
997 // Fetch source image properties
998 $this->get_image_properties();
999
1000 // Set RGB values for text and shadow
1001 $this->wm_font_color = str_replace('#', '', $this->wm_font_color);
1002 $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color);
1003
1004 $R1 = hexdec(substr($this->wm_font_color, 0, 2));
1005 $G1 = hexdec(substr($this->wm_font_color, 2, 2));
1006 $B1 = hexdec(substr($this->wm_font_color, 4, 2));
1007
1008 $R2 = hexdec(substr($this->wm_shadow_color, 0, 2));
1009 $G2 = hexdec(substr($this->wm_shadow_color, 2, 2));
1010 $B2 = hexdec(substr($this->wm_shadow_color, 4, 2));
1011
1012 $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1);
1013 $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2);
1014
1015 // Reverse the vertical offset
1016 // When the image is positioned at the bottom
1017 // we don't want the vertical offset to push it
1018 // further down. We want the reverse, so we'll
1019 // invert the offset. Note: The horizontal
1020 // offset flips itself automatically
1021
1022 if ($this->wm_vrt_alignment == 'B')
1023 $this->wm_vrt_offset = $this->wm_vrt_offset * -1;
1024
1025 if ($this->wm_hor_alignment == 'R')
1026 $this->wm_hor_offset = $this->wm_hor_offset * -1;
1027
1028 // Set font width and height
1029 // These are calculated differently depending on
1030 // whether we are using the true type font or not
1031 if ($this->wm_use_truetype == TRUE)
1032 {
1033 if ($this->wm_font_size == '')
1034 $this->wm_font_size = '17';
1035
1036 $fontwidth = $this->wm_font_size-($this->wm_font_size/4);
1037 $fontheight = $this->wm_font_size;
1038 $this->wm_vrt_offset += $this->wm_font_size;
1039 }
1040 else
1041 {
1042 $fontwidth = imagefontwidth($this->wm_font_size);
1043 $fontheight = imagefontheight($this->wm_font_size);
1044 }
1045
1046 // Set base X and Y axis values
1047 $x_axis = $this->wm_hor_offset + $this->wm_padding;
1048 $y_axis = $this->wm_vrt_offset + $this->wm_padding;
1049
1050 // Set verticle alignment
1051 if ($this->wm_use_drop_shadow == FALSE)
1052 $this->wm_shadow_distance = 0;
1053
1054 $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1));
1055 $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1));
1056
1057 switch ($this->wm_vrt_alignment)
1058 {
1059 case "T" :
1060 break;
1061 case "M": $y_axis += ($this->orig_height/2)+($fontheight/2);
1062 break;
1063 case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2));
1064 break;
1065 }
1066
1067 $x_shad = $x_axis + $this->wm_shadow_distance;
1068 $y_shad = $y_axis + $this->wm_shadow_distance;
1069
1070 // Set horizontal alignment
1071 switch ($this->wm_hor_alignment)
1072 {
1073 case "L":
1074 break;
1075 case "R":
1076 if ($this->wm_use_drop_shadow)
1077 $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text));
1078 $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text));
1079 break;
1080 case "C":
1081 if ($this->wm_use_drop_shadow)
1082 $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2);
1083 $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2);
1084 break;
1085 }
1086
1087 // Add the text to the source image
1088 if ($this->wm_use_truetype)
1089 {
1090 if ($this->wm_use_drop_shadow)
1091 imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text);
1092 imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text);
1093 }
1094 else
1095 {
1096 if ($this->wm_use_drop_shadow)
1097 imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color);
1098 imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color);
1099 }
1100
1101 // Output the final image
1102 if ($this->dynamic_output == TRUE)
1103 {
1104 $this->image_display_gd($src_img);
1105 }
1106 else
1107 {
1108 $this->image_save_gd($src_img);
1109 }
1110
1111 imagedestroy($src_img);
1112
1113 return TRUE;
1114 }
1115
1116 // --------------------------------------------------------------------
1117
1118 /**
1119 * Create Image - GD
1120 *
1121 * This simply creates an image resource handle
1122 * based on the type of image being processed
1123 *
1124 * @access public
1125 * @param string
1126 * @return resource
1127 */
1128 function image_create_gd($path = '', $image_type = '')
1129 {
1130 if ($path == '')
1131 $path = $this->full_src_path;
1132
1133 if ($image_type == '')
1134 $image_type = $this->image_type;
1135
1136
1137 switch ($image_type)
1138 {
1139 case 1 :
Derek Jones0b59f272008-05-13 04:22:33 +00001140 if ( ! function_exists('imagecreatefromgif'))
Derek Allardc5d88792007-02-01 03:12:32 +00001141 {
1142 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1143 return FALSE;
1144 }
1145
1146 return imagecreatefromgif($path);
1147 break;
1148 case 2 :
Derek Jones0b59f272008-05-13 04:22:33 +00001149 if ( ! function_exists('imagecreatefromjpeg'))
Derek Allardc5d88792007-02-01 03:12:32 +00001150 {
1151 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1152 return FALSE;
1153 }
1154
1155 return imagecreatefromjpeg($path);
1156 break;
1157 case 3 :
Derek Jones0b59f272008-05-13 04:22:33 +00001158 if ( ! function_exists('imagecreatefrompng'))
Derek Allardc5d88792007-02-01 03:12:32 +00001159 {
1160 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1161 return FALSE;
1162 }
1163
1164 return imagecreatefrompng($path);
1165 break;
1166
1167 }
1168
1169 $this->set_error(array('imglib_unsupported_imagecreate'));
1170 return FALSE;
1171 }
1172
1173 // --------------------------------------------------------------------
1174
1175 /**
1176 * Write image file to disk - GD
1177 *
1178 * Takes an image resource as input and writes the file
1179 * to the specified destination
1180 *
1181 * @access public
1182 * @param resource
1183 * @return bool
1184 */
1185 function image_save_gd($resource)
1186 {
1187 switch ($this->image_type)
1188 {
1189 case 1 :
Derek Jones0b59f272008-05-13 04:22:33 +00001190 if ( ! function_exists('imagegif'))
Derek Allardc5d88792007-02-01 03:12:32 +00001191 {
1192 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported'));
1193 return FALSE;
1194 }
1195
1196 @imagegif($resource, $this->full_dst_path);
1197 break;
1198 case 2 :
Derek Jones0b59f272008-05-13 04:22:33 +00001199 if ( ! function_exists('imagejpeg'))
Derek Allardc5d88792007-02-01 03:12:32 +00001200 {
1201 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported'));
1202 return FALSE;
1203 }
1204
1205 if (phpversion() == '4.4.1')
1206 {
1207 @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround
1208 }
1209
1210 @imagejpeg($resource, $this->full_dst_path, $this->quality);
1211 break;
1212 case 3 :
Derek Jones0b59f272008-05-13 04:22:33 +00001213 if ( ! function_exists('imagepng'))
Derek Allardc5d88792007-02-01 03:12:32 +00001214 {
1215 $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported'));
1216 return FALSE;
1217 }
1218
1219 @imagepng($resource, $this->full_dst_path);
1220 break;
1221 default :
1222 $this->set_error(array('imglib_unsupported_imagecreate'));
1223 return FALSE;
1224 break;
1225 }
1226
1227 return TRUE;
1228 }
1229
1230 // --------------------------------------------------------------------
1231
1232 /**
1233 * Dynamically outputs an image
1234 *
1235 * @access public
1236 * @param resource
1237 * @return void
1238 */
1239 function image_display_gd($resource)
1240 {
1241 header("Content-Disposition: filename={$this->source_image};");
1242 header("Content-Type: {$this->mime_type}");
1243 header('Content-Transfer-Encoding: binary');
1244 header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT');
1245
1246 switch ($this->image_type)
1247 {
1248 case 1 : imagegif($resource);
1249 break;
1250 case 2 : imagejpeg($resource, '', $this->quality);
1251 break;
1252 case 3 : imagepng($resource);
1253 break;
1254 default : echo 'Unable to display the image';
1255 break;
1256 }
1257 }
1258
1259 // --------------------------------------------------------------------
1260
1261 /**
1262 * Re-proportion Image Width/Height
1263 *
1264 * When creating thumbs, the desired width/height
1265 * can end up warping the image due to an incorrect
1266 * ratio between the full-sized image and the thumb.
1267 *
1268 * This function lets us re-proportion the width/height
1269 * if users choose to maintain the aspect ratio when resizing.
1270 *
1271 * @access public
1272 * @return void
1273 */
1274 function image_reproportion()
1275 {
Derek Jones0b59f272008-05-13 04:22:33 +00001276 if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0)
Derek Allardc5d88792007-02-01 03:12:32 +00001277 return;
1278
Derek Jones0b59f272008-05-13 04:22:33 +00001279 if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0)
Derek Allardc5d88792007-02-01 03:12:32 +00001280 return;
1281
1282 $new_width = ceil($this->orig_width*$this->height/$this->orig_height);
1283 $new_height = ceil($this->width*$this->orig_height/$this->orig_width);
1284
1285 $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width));
1286
1287 if ($this->master_dim != 'width' AND $this->master_dim != 'height')
1288 {
1289 $this->master_dim = ($ratio < 0) ? 'width' : 'height';
1290 }
1291
1292 if (($this->width != $new_width) AND ($this->height != $new_height))
1293 {
1294 if ($this->master_dim == 'height')
1295 {
1296 $this->width = $new_width;
1297 }
1298 else
1299 {
1300 $this->height = $new_height;
1301 }
1302 }
1303 }
1304
1305 // --------------------------------------------------------------------
1306
1307 /**
1308 * Get image properties
1309 *
1310 * A helper function that gets info about the file
1311 *
1312 * @access public
1313 * @param string
1314 * @return mixed
1315 */
1316 function get_image_properties($path = '', $return = FALSE)
1317 {
1318 // For now we require GD but we should
1319 // find a way to determine this using IM or NetPBM
1320
1321 if ($path == '')
1322 $path = $this->full_src_path;
1323
Derek Jones0b59f272008-05-13 04:22:33 +00001324 if ( ! file_exists($path))
Derek Allardc5d88792007-02-01 03:12:32 +00001325 {
1326 $this->set_error('imglib_invalid_path');
1327 return FALSE;
1328 }
1329
1330 $vals = @getimagesize($path);
1331
1332 $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
1333
1334 $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg';
1335
1336 if ($return == TRUE)
1337 {
1338 $v['width'] = $vals['0'];
1339 $v['height'] = $vals['1'];
1340 $v['image_type'] = $vals['2'];
1341 $v['size_str'] = $vals['3'];
1342 $v['mime_type'] = $mime;
1343
1344 return $v;
1345 }
1346
1347 $this->orig_width = $vals['0'];
1348 $this->orig_height = $vals['1'];
1349 $this->image_type = $vals['2'];
1350 $this->size_str = $vals['3'];
1351 $this->mime_type = $mime;
1352
1353 return TRUE;
1354 }
1355
1356 // --------------------------------------------------------------------
1357
1358 /**
1359 * Size calculator
1360 *
1361 * This function takes a known width x height and
1362 * recalculates it to a new size. Only one
1363 * new variable needs to be known
1364 *
1365 * $props = array(
1366 * 'width' => $width,
1367 * 'height' => $height,
1368 * 'new_width' => 40,
1369 * 'new_height' => ''
1370 * );
1371 *
1372 * @access public
1373 * @param array
1374 * @return array
1375 */
1376 function size_calculator($vals)
1377 {
Derek Jones0b59f272008-05-13 04:22:33 +00001378 if ( ! is_array($vals))
Derek Allardc5d88792007-02-01 03:12:32 +00001379 return;
1380
1381 $allowed = array('new_width', 'new_height', 'width', 'height');
1382
1383 foreach ($allowed as $item)
1384 {
Derek Jones0b59f272008-05-13 04:22:33 +00001385 if ( ! isset($vals[$item]) OR $vals[$item] == '')
Derek Allardc5d88792007-02-01 03:12:32 +00001386 $vals[$item] = 0;
1387 }
1388
1389 if ($vals['width'] == 0 OR $vals['height'] == 0)
1390 {
1391 return $vals;
1392 }
1393
1394 if ($vals['new_width'] == 0)
1395 {
1396 $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']);
1397 }
1398 elseif ($vals['new_height'] == 0)
1399 {
1400 $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']);
1401 }
1402
1403 return $vals;
1404 }
1405
1406 // --------------------------------------------------------------------
1407
1408 /**
1409 * Explode source_image
1410 *
1411 * This is a helper function that extracts the extension
1412 * from the source_image. This function lets us deal with
1413 * source_images with multiple periods, like: my.cool.jpg
1414 * It returns an associative array with two elements:
1415 * $array['ext'] = '.jpg';
1416 * $array['name'] = 'my.cool';
1417 *
1418 * @access public
1419 * @param array
1420 * @return array
1421 */
1422 function explode_name($source_image)
1423 {
1424 $x = explode('.', $source_image);
1425 $ret['ext'] = '.'.end($x);
1426
1427 $name = '';
1428
1429 $ct = count($x)-1;
1430
1431 for ($i = 0; $i < $ct; $i++)
1432 {
1433 $name .= $x[$i];
1434
1435 if ($i < ($ct - 1))
1436 {
1437 $name .= '.';
1438 }
1439 }
1440
1441 $ret['name'] = $name;
1442
1443 return $ret;
1444 }
1445
1446 // --------------------------------------------------------------------
1447
1448 /**
1449 * Is GD Installed?
1450 *
1451 * @access public
1452 * @return bool
1453 */
1454 function gd_loaded()
1455 {
Derek Jones0b59f272008-05-13 04:22:33 +00001456 if ( ! extension_loaded('gd'))
Derek Allardc5d88792007-02-01 03:12:32 +00001457 {
Derek Jones0b59f272008-05-13 04:22:33 +00001458 if ( ! dl('gd.so'))
Derek Allardc5d88792007-02-01 03:12:32 +00001459 {
1460 return FALSE;
1461 }
1462 }
1463
1464 return TRUE;
1465 }
1466
1467 // --------------------------------------------------------------------
1468
1469 /**
1470 * Get GD version
1471 *
1472 * @access public
1473 * @return mixed
1474 */
1475 function gd_version()
1476 {
1477 if (function_exists('gd_info'))
1478 {
1479 $gd_version = @gd_info();
1480 $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']);
1481
1482 return $gd_version;
1483 }
1484
1485 return FALSE;
1486 }
1487
1488 // --------------------------------------------------------------------
1489
1490 /**
1491 * Set error message
1492 *
1493 * @access public
1494 * @param string
1495 * @return void
1496 */
1497 function set_error($msg)
1498 {
1499 $CI =& get_instance();
1500 $CI->lang->load('imglib');
1501
1502 if (is_array($msg))
1503 {
1504 foreach ($msg as $val)
1505 {
1506
1507 $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val);
1508 $this->error_msg[] = $msg;
1509 log_message('error', $msg);
1510 }
1511 }
1512 else
1513 {
1514 $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg);
1515 $this->error_msg[] = $msg;
1516 log_message('error', $msg);
1517 }
1518 }
1519
1520 // --------------------------------------------------------------------
1521
1522 /**
1523 * Show error messages
1524 *
1525 * @access public
1526 * @param string
1527 * @return string
1528 */
1529 function display_errors($open = '<p>', $close = '</p>')
1530 {
1531 $str = '';
1532 foreach ($this->error_msg as $val)
1533 {
1534 $str .= $open.$val.$close;
1535 }
1536
1537 return $str;
1538 }
1539
1540}
1541// END Image_lib Class
Derek Jones500fa6c2008-05-12 15:08:35 +00001542
1543/* End of file Image_lib.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +00001544/* Location: ./system/libraries/Image_lib.php */