Image_lib.php 37 KB

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