From cb07a322bee5c5b0a551ab959c7475a1a702ad03 Mon Sep 17 00:00:00 2001 From: Michael Dennis Date: Sat, 20 Aug 2011 23:40:59 -0700 Subject: Fix for the Image_lib clear() function so that it resets all variables to their default values. This should fix issues #157 and #174. https://github.com/EllisLab/CodeIgniter/issues/157 https://github.com/EllisLab/CodeIgniter/issues/174 --- system/libraries/Image_lib.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8902f524d..6855e4498 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -104,15 +104,37 @@ class CI_Image_lib { */ function clear() { - $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'); + $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); foreach ($props as $val) { $this->$val = ''; } - // special consideration for master_dim - $this->master_dim = 'auto'; + $this->image_library = 'gd2'; + $this->dynamic_output = FALSE; + $this->quality = '90'; + $this->create_thumb = FALSE; + $this->thumb_marker = '_thumb'; + $this->maintain_ratio = TRUE; + $this->master_dim = 'auto'; + $this->wm_type = 'text'; + $this->wm_x_transp = 4; + $this->wm_y_transp = 4; + $this->wm_font_size = 17; + $this->wm_vrt_alignment = 'B'; + $this->wm_hor_alignment = 'C'; + $this->wm_padding = 0; + $this->wm_hor_offset = 0; + $this->wm_vrt_offset = 0; + $this->wm_font_color = '#ffffff'; + $this->wm_shadow_distance = 2; + $this->wm_opacity = 50; + $this->create_fnc = 'imagecreatetruecolor'; + $this->copy_fnc = 'imagecopyresampled'; + $this->error_msg = array(); + $this->wm_use_drop_shadow = FALSE; + $this->wm_use_truetype = FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 901998a9a517d96faff5c24fb40f98961f83c3cd Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 26 Aug 2011 10:03:33 +0100 Subject: Removed some error suppression, which would hide a Notice if the path cannot be read. I discovered this by foolishly passing the file_path, not the full_path but took forever for me to realise this as the error returned (thanks to this error suppression) was "GD is not installed" instead of "File cannot be read". Seeing that notice would have made much more sense. --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8902f524d..a8a0387d8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1334,7 +1334,7 @@ class CI_Image_lib { return FALSE; } - $vals = @getimagesize($path); + $vals = getimagesize($path); $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); -- cgit v1.2.3-24-g4f1b From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Image_lib.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index a8a0387d8..beb463b32 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -21,7 +33,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Image_lib - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/image_lib.html */ class CI_Image_lib { -- cgit v1.2.3-24-g4f1b From b840a6704feb7a2439bbd3a9a23127dafc7b42f7 Mon Sep 17 00:00:00 2001 From: Seb Pollard Date: Sat, 22 Oct 2011 23:28:21 +0100 Subject: Fixed an issue with the Image_lib class not clearing width, height or create_thumb properties when calling the clear() method. --- system/libraries/Image_lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index beb463b32..ceb31d1f0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -116,7 +116,7 @@ class CI_Image_lib { */ function clear() { - $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'); + $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', 'width', 'height'); foreach ($props as $val) { @@ -125,6 +125,9 @@ class CI_Image_lib { // special consideration for master_dim $this->master_dim = 'auto'; + + // special consideration for create_thumb + $this->create_thumb = FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4eea9895e8ced75a1099c56215c09773de94b92c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Dec 2011 12:05:41 +0200 Subject: Add method visibility declarations and optimize display_errors() method in Image_lib, Trackback and Upload libraries --- system/libraries/Image_lib.php | 58 +++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 2ed488c7e..c4797e34a 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -114,7 +114,7 @@ class CI_Image_lib { * @access public * @return void */ - function clear() + public function clear() { $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); @@ -158,7 +158,7 @@ class CI_Image_lib { * @param array * @return bool */ - function initialize($props = array()) + public function initialize($props = array()) { /* * Convert array elements into class variables @@ -379,7 +379,7 @@ class CI_Image_lib { * @access public * @return bool */ - function resize() + public function resize() { $protocol = 'image_process_'.$this->image_library; @@ -402,7 +402,7 @@ class CI_Image_lib { * @access public * @return bool */ - function crop() + public function crop() { $protocol = 'image_process_'.$this->image_library; @@ -425,7 +425,7 @@ class CI_Image_lib { * @access public * @return bool */ - function rotate() + public function rotate() { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); @@ -478,7 +478,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_gd($action = 'resize') + public function image_process_gd($action = 'resize') { $v2_override = FALSE; @@ -590,7 +590,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_imagemagick($action = 'resize') + public function image_process_imagemagick($action = 'resize') { // Do we have a vaild library path? if ($this->library_path == '') @@ -660,7 +660,7 @@ class CI_Image_lib { * @param string * @return bool */ - function image_process_netpbm($action = 'resize') + public function image_process_netpbm($action = 'resize') { if ($this->library_path == '') { @@ -743,7 +743,7 @@ class CI_Image_lib { * @access public * @return bool */ - function image_rotate_gd() + public function image_rotate_gd() { // Create the image handle if ( ! ($src_img = $this->image_create_gd())) @@ -796,7 +796,7 @@ class CI_Image_lib { * @access public * @return bool */ - function image_mirror_gd() + public function image_mirror_gd() { if ( ! $src_img = $this->image_create_gd()) { @@ -882,7 +882,7 @@ class CI_Image_lib { * @param string * @return bool */ - function watermark() + public function watermark() { if ($this->wm_type == 'overlay') { @@ -902,7 +902,7 @@ class CI_Image_lib { * @access public * @return bool */ - function overlay_watermark() + public function overlay_watermark() { if ( ! function_exists('imagecolortransparent')) { @@ -1015,7 +1015,7 @@ class CI_Image_lib { * @access public * @return bool */ - function text_watermark() + public function text_watermark() { if ( ! ($src_img = $this->image_create_gd())) { @@ -1159,7 +1159,7 @@ class CI_Image_lib { * @param string * @return resource */ - function image_create_gd($path = '', $image_type = '') + public function image_create_gd($path = '', $image_type = '') { if ($path == '') $path = $this->full_src_path; @@ -1216,7 +1216,7 @@ class CI_Image_lib { * @param resource * @return bool */ - function image_save_gd($resource) + public function image_save_gd($resource) { switch ($this->image_type) { @@ -1277,7 +1277,7 @@ class CI_Image_lib { * @param resource * @return void */ - function image_display_gd($resource) + public function image_display_gd($resource) { header("Content-Disposition: filename={$this->source_image};"); header("Content-Type: {$this->mime_type}"); @@ -1312,7 +1312,7 @@ class CI_Image_lib { * @access public * @return void */ - function image_reproportion() + public function image_reproportion() { if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) return; @@ -1354,7 +1354,7 @@ class CI_Image_lib { * @param string * @return mixed */ - function get_image_properties($path = '', $return = FALSE) + public function get_image_properties($path = '', $return = FALSE) { // For now we require GD but we should // find a way to determine this using IM or NetPBM @@ -1414,7 +1414,7 @@ class CI_Image_lib { * @param array * @return array */ - function size_calculator($vals) + public function size_calculator($vals) { if ( ! is_array($vals)) { @@ -1462,7 +1462,7 @@ class CI_Image_lib { * @param array * @return array */ - function explode_name($source_image) + public function explode_name($source_image) { $ext = strrchr($source_image, '.'); $name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext)); @@ -1478,7 +1478,7 @@ class CI_Image_lib { * @access public * @return bool */ - function gd_loaded() + public function gd_loaded() { if ( ! extension_loaded('gd')) { @@ -1499,7 +1499,7 @@ class CI_Image_lib { * @access public * @return mixed */ - function gd_version() + public function gd_version() { if (function_exists('gd_info')) { @@ -1521,7 +1521,7 @@ class CI_Image_lib { * @param string * @return void */ - function set_error($msg) + public function set_error($msg) { $CI =& get_instance(); $CI->lang->load('imglib'); @@ -1553,19 +1553,13 @@ class CI_Image_lib { * @param string * @return string */ - function display_errors($open = '

', $close = '

') + public function display_errors($open = '

', $close = '

') { - $str = ''; - foreach ($this->error_msg as $val) - { - $str .= $open.$val.$close; - } - - return $str; + return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; } } // END Image_lib Class /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file +/* Location: ./system/libraries/Image_lib.php */ -- cgit v1.2.3-24-g4f1b From 3a45957a30ff908445b2772efac8fdb65b64e6cd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 21 Dec 2011 11:23:11 +0200 Subject: Also replace old-style 'var' with 'public' --- system/libraries/Image_lib.php | 90 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 45 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c4797e34a..20ca1f055 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -38,55 +38,55 @@ */ class CI_Image_lib { - var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 - var $library_path = ''; - var $dynamic_output = FALSE; // Whether to send to browser or write to disk - var $source_image = ''; - var $new_image = ''; - var $width = ''; - var $height = ''; - var $quality = '90'; - var $create_thumb = FALSE; - var $thumb_marker = '_thumb'; - var $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values - var $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension - var $rotation_angle = ''; - var $x_axis = ''; - var $y_axis = ''; + public $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 + public $library_path = ''; + public $dynamic_output = FALSE; // Whether to send to browser or write to disk + public $source_image = ''; + public $new_image = ''; + public $width = ''; + public $height = ''; + public $quality = '90'; + public $create_thumb = FALSE; + public $thumb_marker = '_thumb'; + public $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values + public $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension + public $rotation_angle = ''; + public $x_axis = ''; + public $y_axis = ''; // Watermark Vars - var $wm_text = ''; // Watermark text if graphic is not used - var $wm_type = 'text'; // Type of watermarking. Options: text/overlay - var $wm_x_transp = 4; - var $wm_y_transp = 4; - var $wm_overlay_path = ''; // Watermark image path - var $wm_font_path = ''; // TT font - var $wm_font_size = 17; // Font size (different versions of GD will either use points or pixels) - var $wm_vrt_alignment = 'B'; // Vertical alignment: T M B - var $wm_hor_alignment = 'C'; // Horizontal alignment: L R C - var $wm_padding = 0; // Padding around text - var $wm_hor_offset = 0; // Lets you push text to the right - var $wm_vrt_offset = 0; // Lets you push text down - var $wm_font_color = '#ffffff'; // Text color - var $wm_shadow_color = ''; // Dropshadow color - var $wm_shadow_distance = 2; // Dropshadow distance - var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image + public $wm_text = ''; // Watermark text if graphic is not used + public $wm_type = 'text'; // Type of watermarking. Options: text/overlay + public $wm_x_transp = 4; + public $wm_y_transp = 4; + public $wm_overlay_path = ''; // Watermark image path + public $wm_font_path = ''; // TT font + public $wm_font_size = 17; // Font size (different versions of GD will either use points or pixels) + public $wm_vrt_alignment = 'B'; // Vertical alignment: T M B + public $wm_hor_alignment = 'C'; // Horizontal alignment: L R C + public $wm_padding = 0; // Padding around text + public $wm_hor_offset = 0; // Lets you push text to the right + public $wm_vrt_offset = 0; // Lets you push text down + public $wm_font_color = '#ffffff'; // Text color + public $wm_shadow_color = ''; // Dropshadow color + public $wm_shadow_distance = 2; // Dropshadow distance + public $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image // Private Vars - var $source_folder = ''; - var $dest_folder = ''; - var $mime_type = ''; - var $orig_width = ''; - var $orig_height = ''; - var $image_type = ''; - var $size_str = ''; - var $full_src_path = ''; - var $full_dst_path = ''; - var $create_fnc = 'imagecreatetruecolor'; - var $copy_fnc = 'imagecopyresampled'; - var $error_msg = array(); - var $wm_use_drop_shadow = FALSE; - var $wm_use_truetype = FALSE; + public $source_folder = ''; + public $dest_folder = ''; + public $mime_type = ''; + public $orig_width = ''; + public $orig_height = ''; + public $image_type = ''; + public $size_str = ''; + public $full_src_path = ''; + public $full_dst_path = ''; + public $create_fnc = 'imagecreatetruecolor'; + public $copy_fnc = 'imagecopyresampled'; + public $error_msg = array(); + public $wm_use_drop_shadow = FALSE; + public $wm_use_truetype = FALSE; /** * Constructor -- cgit v1.2.3-24-g4f1b From a92b903c0e6c2faa2a9480e23e2d3e4b6308878f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 24 Dec 2011 19:05:58 +0200 Subject: Improve the Image manipulation library --- system/libraries/Image_lib.php | 150 ++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 92 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 20ca1f055..70a127987 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ -y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... - if ($this->wm_font_color != '') + if ($this->wm_font_color != '' AND strlen($this->wm_font_color) === 6) { - if (strlen($this->wm_font_color) == 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } + $this->wm_font_color = '#'.$this->wm_font_color; } - if ($this->wm_shadow_color != '') + if ($this->wm_shadow_color != '' AND strlen($this->wm_shadow_color) === 6) { - if (strlen($this->wm_shadow_color) == 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } + $this->wm_shadow_color = '#'.$this->wm_shadow_color; } if ($this->wm_overlay_path != '') @@ -381,13 +375,7 @@ class CI_Image_lib { */ public function resize() { - $protocol = 'image_process_'.$this->image_library; - - if (preg_match('/gd2$/i', $protocol)) - { - $protocol = 'image_process_gd'; - } - + $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('resize'); } @@ -404,13 +392,7 @@ class CI_Image_lib { */ public function crop() { - $protocol = 'image_process_'.$this->image_library; - - if (preg_match('/gd2$/i', $protocol)) - { - $protocol = 'image_process_gd'; - } - + $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('crop'); } @@ -453,7 +435,6 @@ class CI_Image_lib { if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') { $protocol = 'image_process_'.$this->image_library; - return $this->$protocol('rotate'); } @@ -484,20 +465,14 @@ class CI_Image_lib { // If the target width/height match the source, AND if the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE) + if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height) { - if ($this->orig_width == $this->width AND $this->orig_height == $this->height) + if ($this->source_image != $this->new_image AND @copy($this->full_src_path, $this->full_dst_path)) { - if ($this->source_image != $this->new_image) - { - if (@copy($this->full_src_path, $this->full_dst_path)) - { - @chmod($this->full_dst_path, FILE_WRITE_MODE); - } - } - - return TRUE; + @chmod($this->full_dst_path, FILE_WRITE_MODE); } + + return TRUE; } // Let's set up our values based on the action @@ -601,9 +576,7 @@ class CI_Image_lib { if ( ! preg_match("/convert$/i", $this->library_path)) { - $this->library_path = rtrim($this->library_path, '/').'/'; - - $this->library_path .= 'convert'; + $this->library_path = rtrim($this->library_path, '/').'/convert'; } // Execute the command @@ -808,11 +781,8 @@ class CI_Image_lib { if ($this->rotation_angle == 'hor') { - for ($i = 0; $i < $height; $i++) + for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) { - $left = 0; - $right = $width-1; - while ($left < $right) { $cl = imagecolorat($src_img, $left, $i); @@ -828,11 +798,8 @@ class CI_Image_lib { } else { - for ($i = 0; $i < $width; $i++) + for ($i = 0; $i < $width; $i++, $top = 0, $bot = $height-1) { - $top = 0; - $bot = $height-1; - while ($top < $bot) { $ct = imagecolorat($src_img, $i, $top); @@ -993,12 +960,9 @@ class CI_Image_lib { { $this->image_display_gd($src_img); } - else + elseif ( ! $this->image_save_gd($src_img)) { - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } + return FALSE; } imagedestroy($src_img); @@ -1065,7 +1029,9 @@ class CI_Image_lib { if ($this->wm_use_truetype == TRUE) { if ($this->wm_font_size == '') - $this->wm_font_size = '17'; + { + $this->wm_font_size = 17; + } $fontwidth = $this->wm_font_size-($this->wm_font_size/4); $fontheight = $this->wm_font_size; @@ -1090,11 +1056,11 @@ class CI_Image_lib { switch ($this->wm_vrt_alignment) { - case "T" : + case 'T': break; - case "M": $y_axis += ($this->orig_height/2)+($fontheight/2); + case 'M': $y_axis += ($this->orig_height/2)+($fontheight/2); break; - case "B": $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); + case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); break; } @@ -1104,32 +1070,34 @@ class CI_Image_lib { // Set horizontal alignment switch ($this->wm_hor_alignment) { - case "L": + case 'L': break; - case "R": - if ($this->wm_use_drop_shadow) - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + case 'R': + if ($this->wm_use_drop_shadow) + { + $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); + } break; - case "C": - if ($this->wm_use_drop_shadow) - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width -$fontwidth*strlen($this->wm_text))/2); + case 'C': + if ($this->wm_use_drop_shadow) + { + $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + $x_axis += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); + } break; } // Add the text to the source image - if ($this->wm_use_truetype) + if ($this->wm_use_truetype AND $this->wm_use_drop_shadow) { - if ($this->wm_use_drop_shadow) - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); } - else + elseif ($this->wm_use_drop_shadow) { - if ($this->wm_use_drop_shadow) - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } // Output the final image @@ -1369,26 +1337,24 @@ class CI_Image_lib { } $vals = getimagesize($path); - $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - - $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg'; + $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; if ($return == TRUE) { - $v['width'] = $vals['0']; - $v['height'] = $vals['1']; - $v['image_type'] = $vals['2']; - $v['size_str'] = $vals['3']; - $v['mime_type'] = $mime; - - return $v; + return array( + 'width' => $vals[0], + 'height' => $vals[1], + 'image_type' => $vals[2], + 'size_str' => $vals[3], + 'mime_type' => $mime + ); } - $this->orig_width = $vals['0']; - $this->orig_height = $vals['1']; - $this->image_type = $vals['2']; - $this->size_str = $vals['3']; + $this->orig_width = $vals[0]; + $this->orig_height = $vals[1]; + $this->image_type = $vals[2]; + $this->size_str = $vals[3]; $this->mime_type = $mime; return TRUE; @@ -1482,10 +1448,10 @@ class CI_Image_lib { { if ( ! extension_loaded('gd')) { - if ( ! dl('gd.so')) - { - return FALSE; - } + /* As it is stated in the PHP manual, dl() is not always available + * and even if so - it could generate an E_WARNING message on failure + */ + return (function_exists('dl') AND @dl('gd.so')); } return TRUE; -- cgit v1.2.3-24-g4f1b From 5342e8b0d8e4c0b585a4757d60f0fd7127704755 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 02:57:52 +0200 Subject: Remove access lines from method descriptions --- system/libraries/Image_lib.php | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 70a127987..2737503a8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -111,7 +111,6 @@ class CI_Image_lib { * * Resets values in case this class is used in a loop * - * @access public * @return void */ public function clear() @@ -154,7 +153,6 @@ class CI_Image_lib { /** * initialize image preferences * - * @access public * @param array * @return bool */ @@ -370,7 +368,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * resize function based on the protocol specified * - * @access public * @return bool */ public function resize() @@ -387,7 +384,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * cropping function based on the protocol specified * - * @access public * @return bool */ public function crop() @@ -404,7 +400,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the proper * rotation function based on the protocol specified * - * @access public * @return bool */ public function rotate() @@ -455,7 +450,6 @@ class CI_Image_lib { * * This function will resize or crop * - * @access public * @param string * @return bool */ @@ -561,7 +555,6 @@ class CI_Image_lib { * * This function will resize, crop or rotate * - * @access public * @param string * @return bool */ @@ -629,7 +622,6 @@ class CI_Image_lib { * * This function will resize, crop or rotate * - * @access public * @param string * @return bool */ @@ -713,7 +705,6 @@ class CI_Image_lib { /** * Image Rotate Using GD * - * @access public * @return bool */ public function image_rotate_gd() @@ -766,7 +757,6 @@ class CI_Image_lib { * * This function will flip horizontal or vertical * - * @access public * @return bool */ public function image_mirror_gd() @@ -845,7 +835,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the type * of watermarking based on the specified preference. * - * @access public * @param string * @return bool */ @@ -866,7 +855,6 @@ class CI_Image_lib { /** * Watermark - Graphic Version * - * @access public * @return bool */ public function overlay_watermark() @@ -976,7 +964,6 @@ class CI_Image_lib { /** * Watermark - Text Version * - * @access public * @return bool */ public function text_watermark() @@ -1123,7 +1110,6 @@ class CI_Image_lib { * This simply creates an image resource handle * based on the type of image being processed * - * @access public * @param string * @return resource */ @@ -1180,7 +1166,6 @@ class CI_Image_lib { * Takes an image resource as input and writes the file * to the specified destination * - * @access public * @param resource * @return bool */ @@ -1241,7 +1226,6 @@ class CI_Image_lib { /** * Dynamically outputs an image * - * @access public * @param resource * @return void */ @@ -1277,7 +1261,6 @@ class CI_Image_lib { * This function lets us re-proportion the width/height * if users choose to maintain the aspect ratio when resizing. * - * @access public * @return void */ public function image_reproportion() @@ -1318,7 +1301,6 @@ class CI_Image_lib { * * A helper function that gets info about the file * - * @access public * @param string * @return mixed */ @@ -1376,7 +1358,6 @@ class CI_Image_lib { * 'new_height' => '' * ); * - * @access public * @param array * @return array */ @@ -1424,7 +1405,6 @@ class CI_Image_lib { * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; * - * @access public * @param array * @return array */ @@ -1441,7 +1421,6 @@ class CI_Image_lib { /** * Is GD Installed? * - * @access public * @return bool */ public function gd_loaded() @@ -1462,7 +1441,6 @@ class CI_Image_lib { /** * Get GD version * - * @access public * @return mixed */ public function gd_version() @@ -1483,7 +1461,6 @@ class CI_Image_lib { /** * Set error message * - * @access public * @param string * @return void */ @@ -1515,7 +1492,6 @@ class CI_Image_lib { /** * Show error messages * - * @access public * @param string * @return string */ -- cgit v1.2.3-24-g4f1b From 64dbdfb60e0556177061db2eecdf899111ae4ac9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:14:07 +0200 Subject: Added support for 3-length hex color values format and a number of validation improvements --- system/libraries/Image_lib.php | 87 ++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 38 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 2737503a8..d4fb51923 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -67,8 +67,8 @@ class CI_Image_lib { public $wm_padding = 0; // Padding around text public $wm_hor_offset = 0; // Lets you push text to the right public $wm_vrt_offset = 0; // Lets you push text down - public $wm_font_color = '#ffffff'; // Text color - public $wm_shadow_color = ''; // Dropshadow color + protected $wm_font_color = '#ffffff'; // Text color + protected $wm_shadow_color = ''; // Dropshadow color public $wm_shadow_distance = 2; // Dropshadow distance public $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image @@ -85,7 +85,7 @@ class CI_Image_lib { public $create_fnc = 'imagecreatetruecolor'; public $copy_fnc = 'imagecopyresampled'; public $error_msg = array(); - public $wm_use_drop_shadow = FALSE; + protected $wm_use_drop_shadow = FALSE; public $wm_use_truetype = FALSE; /** @@ -165,7 +165,30 @@ class CI_Image_lib { { foreach ($props as $key => $val) { - $this->$key = $val; + if (property_exists($this, $key)) + { + if (in_array($key, array('wm_font_color', 'wm_shadow_color'))) + { + if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) + { + if (strlen($matches[1]) === 6) + { + $val = '#'.$val; + } + else + { + $val = str_split($val, 1); + $val = '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; + } + } + else + { + continue; + } + } + + $this->$key = $val; + } } } @@ -332,16 +355,6 @@ class CI_Image_lib { $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... - if ($this->wm_font_color != '' AND strlen($this->wm_font_color) === 6) - { - $this->wm_font_color = '#'.$this->wm_font_color; - } - - if ($this->wm_shadow_color != '' AND strlen($this->wm_shadow_color) === 6) - { - $this->wm_shadow_color = '#'.$this->wm_shadow_color; - } - if ($this->wm_overlay_path != '') { $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); @@ -351,6 +364,10 @@ class CI_Image_lib { { $this->wm_use_drop_shadow = TRUE; } + elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '') + { + $this->wm_use_drop_shadow = FALSE; + } if ($this->wm_font_path != '') { @@ -982,21 +999,6 @@ class CI_Image_lib { // Fetch source image properties $this->get_image_properties(); - // Set RGB values for text and shadow - $this->wm_font_color = str_replace('#', '', $this->wm_font_color); - $this->wm_shadow_color = str_replace('#', '', $this->wm_shadow_color); - - $R1 = hexdec(substr($this->wm_font_color, 0, 2)); - $G1 = hexdec(substr($this->wm_font_color, 2, 2)); - $B1 = hexdec(substr($this->wm_font_color, 4, 2)); - - $R2 = hexdec(substr($this->wm_shadow_color, 0, 2)); - $G2 = hexdec(substr($this->wm_shadow_color, 2, 2)); - $B2 = hexdec(substr($this->wm_shadow_color, 4, 2)); - - $txt_color = imagecolorclosest($src_img, $R1, $G1, $B1); - $drp_color = imagecolorclosest($src_img, $R2, $G2, $B2); - // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it @@ -1075,16 +1077,25 @@ class CI_Image_lib { break; } - // Add the text to the source image - if ($this->wm_use_truetype AND $this->wm_use_drop_shadow) - { - imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); - } - elseif ($this->wm_use_drop_shadow) + if ($this->wm_use_drop_shadow) { - imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + // Set RGB values for text and shadow + $txt_color = str_split(substr($this->wm_font_color, 1, 6)); + $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); + $drp_color = str_split(substr($this->wm_shadow_color, 1, 6)); + $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[2]), hexdec($drp_color[3])); + + // Add the text to the source image + if ($this->wm_use_truetype) + { + imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } } // Output the final image -- cgit v1.2.3-24-g4f1b From a948f07bde83e149d9fc75e9aaf7260efba39b55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:22:50 +0200 Subject: Remove a str_split() from the previous commit - we can access string characters like we do in an indexed array anyways --- system/libraries/Image_lib.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d4fb51923..72621c9b4 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,15 +171,7 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - if (strlen($matches[1]) === 6) - { - $val = '#'.$val; - } - else - { - $val = str_split($val, 1); - $val = '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; - } + $val = (strlen($matches[1]) === 6) ? '#'.$val : '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; } else { -- cgit v1.2.3-24-g4f1b From 1d97f291fa1988794b0e6ac2b90a0b1f8c83df25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:24:59 +0200 Subject: Another fix on a previous commit from this request --- system/libraries/Image_lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 72621c9b4..609cb7f98 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,7 +171,8 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - $val = (strlen($matches[1]) === 6) ? '#'.$val : '#'.$val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; + $val = (strlen($matches[1]) === 6) ? + '#'.$matches[1] : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; } else { -- cgit v1.2.3-24-g4f1b From 665af0cbb98372f8521298aafcde9e0c9023123e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Dec 2011 14:39:29 +0200 Subject: Some alignment for readability --- system/libraries/Image_lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 609cb7f98..7beac0ba0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,8 +171,9 @@ class CI_Image_lib { { if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - $val = (strlen($matches[1]) === 6) ? - '#'.$matches[1] : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; + $val = (strlen($matches[1]) === 6) + ? '#'.$matches[1] + : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; } else { -- cgit v1.2.3-24-g4f1b From 8323ae6cebde490bc29141d8dadbdbc07a1c6a4a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 31 Dec 2011 18:39:10 +0200 Subject: Fix a bug and put some comments describing changes from pull #818 --- system/libraries/Image_lib.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 7beac0ba0..c175c6740 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -169,8 +169,21 @@ class CI_Image_lib { { if (in_array($key, array('wm_font_color', 'wm_shadow_color'))) { - if ($val != '' AND preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) + if (preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { + /* This particular line has caused a lengthy discussion + * (https://github.com/EllisLab/CodeIgniter/pull/818), so + * just to clarify: + * + * $matches[1] contains our hex color value, but it might be + * both in the full 6-length format or the shortened 3-length + * value. + * We'll later need the full version, so if we keep it if it's + * already there and if not - we'll convert to it. We can + * access string characters by their index as in an array, + * so we'll do that and use concatenation to form the final + * value: + */ $val = (strlen($matches[1]) === 6) ? '#'.$matches[1] : '#'.$matches[1][0].$matches[1][0].$matches[1][1].$matches[1][1].$matches[1][2].$matches[1][2]; @@ -1073,10 +1086,15 @@ class CI_Image_lib { if ($this->wm_use_drop_shadow) { - // Set RGB values for text and shadow - $txt_color = str_split(substr($this->wm_font_color, 1, 6)); + /* Set RGB values for text and shadow + * + * First character is #, so we don't really need it. + * Get the rest of the string and split it into 2-length + * hex values: + */ + $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); - $drp_color = str_split(substr($this->wm_shadow_color, 1, 6)); + $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[2]), hexdec($drp_color[3])); // Add the text to the source image -- cgit v1.2.3-24-g4f1b From bb96c8b466cb618c5fd6f004234a137011a7e374 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 31 Dec 2011 18:48:39 +0200 Subject: Fix a comment typo --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c175c6740..5f5b5f9d5 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -178,7 +178,7 @@ class CI_Image_lib { * $matches[1] contains our hex color value, but it might be * both in the full 6-length format or the shortened 3-length * value. - * We'll later need the full version, so if we keep it if it's + * We'll later need the full version, so we keep it if it's * already there and if not - we'll convert to it. We can * access string characters by their index as in an array, * so we'll do that and use concatenation to form the final -- cgit v1.2.3-24-g4f1b From cf2ba9ee5fc50b8411eba46ddd73c59b66524fea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 1 Jan 2012 21:57:13 +0200 Subject: Cut some comments --- system/libraries/Image_lib.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 5f5b5f9d5..fe9b8dc79 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -171,11 +171,7 @@ class CI_Image_lib { { if (preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { - /* This particular line has caused a lengthy discussion - * (https://github.com/EllisLab/CodeIgniter/pull/818), so - * just to clarify: - * - * $matches[1] contains our hex color value, but it might be + /* $matches[1] contains our hex color value, but it might be * both in the full 6-length format or the shortened 3-length * value. * We'll later need the full version, so we keep it if it's -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index fe9b8dc79..c86224ffb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 1a9f52c8ec021f6169b977ee936bb8cf2b972230 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 01:06:34 +0200 Subject: Fixed a bug in CI_Image_lib::resize() --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c86224ffb..39f9887f1 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -392,7 +392,7 @@ class CI_Image_lib { */ public function resize() { - $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; + $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('resize'); } -- cgit v1.2.3-24-g4f1b From 5a67e3d09fe934af6f1bd75bb4e3dac87eb1361f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 01:21:09 +0200 Subject: Fix the same expression in crop() --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 39f9887f1..dc7d362ce 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -408,7 +408,7 @@ class CI_Image_lib { */ public function crop() { - $protocol = (strtolower(substr($this->image_library, 0, -3)) === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; + $protocol = ($this->image_library === 'gd2') ? 'image_process_gd' : 'image_process_'.$this->image_library; return $this->$protocol('crop'); } -- cgit v1.2.3-24-g4f1b From 8f80bc4f855f78efbcb6344ea29cf67647b6772b Mon Sep 17 00:00:00 2001 From: Ronald Beilsma Date: Thu, 12 Jan 2012 16:41:49 +0100 Subject: array keys should be 0, 1, and 2. key 3 results in error (invalid offset) --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index dc7d362ce..a226ae8f8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1091,7 +1091,7 @@ class CI_Image_lib { $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); - $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[2]), hexdec($drp_color[3])); + $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); // Add the text to the source image if ($this->wm_use_truetype) -- cgit v1.2.3-24-g4f1b From 8e70b7935181ff56a340a3388080bf4ac6f3428f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 12 Jan 2012 20:19:24 +0200 Subject: CI_Image_lib::image_reproportion() to work if only one of either width or height are set --- system/libraries/Image_lib.php | 195 +++++++++++++++++++---------------------- 1 file changed, 88 insertions(+), 107 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index a226ae8f8..8430d60df 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -88,12 +88,6 @@ class CI_Image_lib { protected $wm_use_drop_shadow = FALSE; public $wm_use_truetype = FALSE; - /** - * Constructor - * - * @param string - * @return void - */ public function __construct($props = array()) { if (count($props) > 0) @@ -101,7 +95,7 @@ class CI_Image_lib { $this->initialize($props); } - log_message('debug', "Image Lib Class Initialized"); + log_message('debug', 'Image Lib Class Initialized'); } // -------------------------------------------------------------------- @@ -158,9 +152,7 @@ class CI_Image_lib { */ public function initialize($props = array()) { - /* - * Convert array elements into class variables - */ + // Convert array elements into class variables if (count($props) > 0) { foreach ($props as $key => $val) @@ -199,7 +191,6 @@ class CI_Image_lib { * Is there a source image? * * If not, there's no reason to continue - * */ if ($this->source_image == '') { @@ -213,7 +204,6 @@ class CI_Image_lib { * We use it to determine the image properties (width/height). * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM - * */ if ( ! function_exists('getimagesize')) { @@ -229,11 +219,10 @@ class CI_Image_lib { * The source image may or may not contain a path. * Either way, we'll try use realpath to generate the * full server path in order to more reliably read it. - * */ - if (function_exists('realpath') AND @realpath($this->source_image) !== FALSE) + if (function_exists('realpath') && @realpath($this->source_image) !== FALSE) { - $full_source_path = str_replace("\\", "/", realpath($this->source_image)); + $full_source_path = str_replace('\\', '/', realpath($this->source_image)); } else { @@ -257,7 +246,6 @@ class CI_Image_lib { * we are making a copy of the source image. If not * it means we are altering the original. We'll * set the destination filename and path accordingly. - * */ if ($this->new_image == '') { @@ -273,9 +261,9 @@ class CI_Image_lib { } else { - if (function_exists('realpath') AND @realpath($this->new_image) !== FALSE) + if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) { - $full_dest_path = str_replace("\\", "/", realpath($this->new_image)); + $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } else { @@ -283,7 +271,7 @@ class CI_Image_lib { } // Is there a file name? - if ( ! preg_match("#\.(jpg|jpeg|gif|png)$#i", $full_dest_path)) + if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) { $this->dest_folder = $full_dest_path.'/'; $this->dest_image = $this->source_image; @@ -305,7 +293,6 @@ class CI_Image_lib { * full server path to the destination image. * We'll also split the destination image name * so we can insert the thumbnail marker if needed. - * */ if ($this->create_thumb === FALSE OR $this->thumb_marker == '') { @@ -325,10 +312,9 @@ class CI_Image_lib { * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source - * image's width/height. We'll recalculate it here. - * + * image's width/height. We'll recalculate it here. */ - if ($this->maintain_ratio === TRUE && ($this->width != '' AND $this->height != '')) + if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0)) { $this->image_reproportion(); } @@ -339,35 +325,40 @@ class CI_Image_lib { * If the destination width/height was * not submitted we will use the values * from the actual file - * */ if ($this->width == '') + { $this->width = $this->orig_width; + } if ($this->height == '') + { $this->height = $this->orig_height; + } // Set the quality - $this->quality = trim(str_replace("%", "", $this->quality)); + $this->quality = trim(str_replace('%', '', $this->quality)); - if ($this->quality == '' OR $this->quality == 0 OR ! is_numeric($this->quality)) + if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) + { $this->quality = 90; + } // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! is_numeric($this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! is_numeric($this->y_axis)) ? 0 : $this->y_axis; + $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... if ($this->wm_overlay_path != '') { - $this->wm_overlay_path = str_replace("\\", "/", realpath($this->wm_overlay_path)); + $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path)); } if ($this->wm_shadow_color != '') { $this->wm_use_drop_shadow = TRUE; } - elseif ($this->wm_use_drop_shadow == TRUE AND $this->wm_shadow_color == '') + elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '') { $this->wm_use_drop_shadow = FALSE; } @@ -445,7 +436,6 @@ class CI_Image_lib { $this->height = $this->orig_height; } - // Choose resizing function if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') { @@ -479,9 +469,9 @@ class CI_Image_lib { // If the target width/height match the source, AND if the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE AND $this->orig_width == $this->width AND $this->orig_height == $this->height) + if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height) { - if ($this->source_image != $this->new_image AND @copy($this->full_src_path, $this->full_dst_path)) + if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) { @chmod($this->full_dst_path, FILE_WRITE_MODE); } @@ -523,7 +513,7 @@ class CI_Image_lib { // below should that ever prove inaccurate. // // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) - if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) + if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; $copy = 'imagecopyresampled'; @@ -587,7 +577,7 @@ class CI_Image_lib { return FALSE; } - if ( ! preg_match("/convert$/i", $this->library_path)) + if ( ! preg_match('/convert$/i', $this->library_path)) { $this->library_path = rtrim($this->library_path, '/').'/convert'; } @@ -597,7 +587,7 @@ class CI_Image_lib { if ($action == 'crop') { - $cmd .= " -crop ".$this->width."x".$this->height."+".$this->x_axis."+".$this->y_axis." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1'; } elseif ($action == 'rotate') { @@ -611,18 +601,17 @@ class CI_Image_lib { break; } - $cmd .= " ".$angle." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } - else // Resize + else // Resize { - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + $cmd .= ' -resize '.$this->width.'x'.$this->height.'" "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } $retval = 1; - @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -700,10 +689,9 @@ class CI_Image_lib { $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; $retval = 1; - @exec($cmd, $output, $retval); - // Did it work? + // Did it work? if ($retval > 0) { $this->set_error('imglib_image_process_failed'); @@ -742,29 +730,24 @@ class CI_Image_lib { $white = imagecolorallocate($src_img, 255, 255, 255); - // Rotate it! + // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); - // Save the Image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); } - else + elseif ( ! $this->image_save_gd($dst_img)) // ... or save it { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; @@ -824,21 +807,17 @@ class CI_Image_lib { } } - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); } - else + elseif ( ! $this->image_save_gd($src_img)) // ... or save it { - // Or save it - if ( ! $this->image_save_gd($src_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($src_img); // Set the file to 777 @@ -860,14 +839,7 @@ class CI_Image_lib { */ public function watermark() { - if ($this->wm_type == 'overlay') - { - return $this->overlay_watermark(); - } - else - { - return $this->text_watermark(); - } + return ($this->wm_type == 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); } // -------------------------------------------------------------------- @@ -885,28 +857,28 @@ class CI_Image_lib { return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); - // Fetch watermark image properties + // Fetch watermark image properties $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; $wm_width = $props['width']; $wm_height = $props['height']; - // Create two image resources + // Create two image resources $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); $src_img = $this->image_create_gd($this->full_src_path); // Reverse the offset if necessary // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll - // invert the offset. Same with the horizontal + // further down. We want the reverse, so we'll + // invert the offset. Same with the horizontal // offset when the image is at the right - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); + $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); if ($this->wm_vrt_alignment == 'B') $this->wm_vrt_offset = $this->wm_vrt_offset * -1; @@ -914,11 +886,11 @@ class CI_Image_lib { if ($this->wm_hor_alignment == 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; - // Set the base x and y axis values + // Set the base x and y axis values $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set the vertical position + // Set the vertical position switch ($this->wm_vrt_alignment) { case 'T': @@ -929,7 +901,7 @@ class CI_Image_lib { break; } - // Set the horizontal position + // Set the horizontal position switch ($this->wm_hor_alignment) { case 'L': @@ -941,7 +913,7 @@ class CI_Image_lib { } // Build the finalized image - if ($wm_img_type == 3 AND function_exists('imagealphablending')) + if ($wm_img_type == 3 && function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); } @@ -993,20 +965,20 @@ class CI_Image_lib { return FALSE; } - if ($this->wm_use_truetype == TRUE AND ! file_exists($this->wm_font_path)) + if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path)) { $this->set_error('imglib_missing_font'); return FALSE; } - // Fetch source image properties + // Fetch source image properties $this->get_image_properties(); // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it // further down. We want the reverse, so we'll - // invert the offset. Note: The horizontal + // invert the offset. Note: The horizontal // offset flips itself automatically if ($this->wm_vrt_alignment == 'B') @@ -1093,7 +1065,7 @@ class CI_Image_lib { $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); - // Add the text to the source image + // Add the text to the source image if ($this->wm_use_truetype) { imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); @@ -1106,7 +1078,7 @@ class CI_Image_lib { } } - // Output the final image + // Output the final image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); @@ -1284,33 +1256,43 @@ class CI_Image_lib { */ public function image_reproportion() { - if ( ! is_numeric($this->width) OR ! is_numeric($this->height) OR $this->width == 0 OR $this->height == 0) - return; - - if ( ! is_numeric($this->orig_width) OR ! is_numeric($this->orig_height) OR $this->orig_width == 0 OR $this->orig_height == 0) - return; - - $new_width = ceil($this->orig_width*$this->height/$this->orig_height); - $new_height = ceil($this->width*$this->orig_height/$this->orig_width); - - $ratio = (($this->orig_height/$this->orig_width) - ($this->height/$this->width)); - - if ($this->master_dim != 'width' AND $this->master_dim != 'height') + if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0 + OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height)) + OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height)) { - $this->master_dim = ($ratio < 0) ? 'width' : 'height'; + return; } - if (($this->width != $new_width) AND ($this->height != $new_height)) + // Sanitize so we don't call preg_match() anymore + $this->width = (int) $this->width; + $this->height = (int) $this->height; + + if ($this->master_dim !== 'width' && $this->master_dim !== 'height') { - if ($this->master_dim == 'height') + if ($this->width > 0 && $this->height > 0) { - $this->width = $new_width; + $this->master_dim = ((($this->orig_height/$this->orig_width) - ($this->height/$this->width)) < 0) + ? 'width' : 'height'; } else { - $this->height = $new_height; + $this->master_dim = ($this->height === 0) ? 'width' : 'height'; } } + elseif (($this->master_dim === 'width' && $this->width === 0) + OR ($this->master_dim === 'height' && $this->height === 0)) + { + return; + } + + if ($this->master_dim === 'width') + { + $this->height = (int) ceil($this->width*$this->orig_height/$this->orig_width); + } + else + { + $this->width = (int) ceil($this->orig_width*$this->height/$this->orig_height); + } } // -------------------------------------------------------------------- @@ -1329,7 +1311,9 @@ class CI_Image_lib { // find a way to determine this using IM or NetPBM if ($path == '') + { $path = $this->full_src_path; + } if ( ! file_exists($path)) { @@ -1449,7 +1433,7 @@ class CI_Image_lib { /* As it is stated in the PHP manual, dl() is not always available * and even if so - it could generate an E_WARNING message on failure */ - return (function_exists('dl') AND @dl('gd.so')); + return (function_exists('dl') && @dl('gd.so')); } return TRUE; @@ -1467,9 +1451,7 @@ class CI_Image_lib { if (function_exists('gd_info')) { $gd_version = @gd_info(); - $gd_version = preg_replace("/\D/", "", $gd_version['GD Version']); - - return $gd_version; + return preg_replace('/\D/', '', $gd_version['GD Version']); } return FALSE; @@ -1520,7 +1502,6 @@ class CI_Image_lib { } } -// END Image_lib Class /* End of file Image_lib.php */ /* Location: ./system/libraries/Image_lib.php */ -- cgit v1.2.3-24-g4f1b From e46363083ad18c93c73a200c9a97934608bb5bab Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 12 Jan 2012 20:23:27 +0200 Subject: Remove a quote --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 8430d60df..fd3cd0edb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -605,7 +605,7 @@ class CI_Image_lib { } else // Resize { - $cmd .= ' -resize '.$this->width.'x'.$this->height.'" "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } $retval = 1; -- cgit v1.2.3-24-g4f1b From 2c8baeb0ecdd3f5db299dc8d66edc2f157b64f23 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2012 15:45:28 +0200 Subject: Some more cleaning --- system/libraries/Image_lib.php | 250 +++++++++++++++++------------------------ 1 file changed, 104 insertions(+), 146 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index fd3cd0edb..065f479e8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Image Manipulation class * @@ -187,22 +185,17 @@ class CI_Image_lib { } } - /* - * Is there a source image? - * - * If not, there's no reason to continue - */ + // Is there a source image? If not, there's no reason to continue if ($this->source_image == '') { $this->set_error('imglib_source_image_required'); return FALSE; } - /* - * Is getimagesize() Available? + /* Is getimagesize() available? * * We use it to determine the image properties (width/height). - * Note: We need to figure out how to determine image + * Note: We need to figure out how to determine image * properties using ImageMagick and NetPBM */ if ( ! function_exists('getimagesize')) @@ -213,8 +206,7 @@ class CI_Image_lib { $this->image_library = strtolower($this->image_library); - /* - * Set the full server path + /* Set the full server path * * The source image may or may not contain a path. * Either way, we'll try use realpath to generate the @@ -244,7 +236,7 @@ class CI_Image_lib { * * If the user has set a "new_image" name it means * we are making a copy of the source image. If not - * it means we are altering the original. We'll + * it means we are altering the original. We'll * set the destination filename and path accordingly. */ if ($this->new_image == '') @@ -252,41 +244,37 @@ class CI_Image_lib { $this->dest_image = $this->source_image; $this->dest_folder = $this->source_folder; } + elseif (strpos($this->new_image, '/') === FALSE) + { + $this->dest_folder = $this->source_folder; + $this->dest_image = $this->new_image; + } else { - if (strpos($this->new_image, '/') === FALSE) + if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) { - $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; + $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } else { - if (function_exists('realpath') && @realpath($this->new_image) !== FALSE) - { - $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } + $full_dest_path = $this->new_image; + } - // Is there a file name? - if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) - { - $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; - } - else - { - $x = explode('/', $full_dest_path); - $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); - } + // Is there a file name? + if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) + { + $this->dest_folder = $full_dest_path.'/'; + $this->dest_image = $this->source_image; + } + else + { + $x = explode('/', $full_dest_path); + $this->dest_image = end($x); + $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); } } - /* - * Compile the finalized filenames/paths + /* Compile the finalized filenames/paths * * We'll create two master strings containing the * full server path to the source image and the @@ -299,7 +287,7 @@ class CI_Image_lib { $this->thumb_marker = ''; } - $xp = $this->explode_name($this->dest_image); + $xp = $this->explode_name($this->dest_image); $filename = $xp['name']; $file_ext = $xp['ext']; @@ -307,8 +295,7 @@ class CI_Image_lib { $this->full_src_path = $this->source_folder.$this->source_image; $this->full_dst_path = $this->dest_folder.$filename.$this->thumb_marker.$file_ext; - /* - * Should we maintain image proportions? + /* Should we maintain image proportions? * * When creating thumbs or copies, the target width/height * might not be in correct proportion with the source @@ -319,12 +306,10 @@ class CI_Image_lib { $this->image_reproportion(); } - /* - * Was a width and height specified? + /* Was a width and height specified? * - * If the destination width/height was - * not submitted we will use the values - * from the actual file + * If the destination width/height was not submitted we + * will use the values from the actual file */ if ($this->width == '') { @@ -437,20 +422,15 @@ class CI_Image_lib { } // Choose resizing function - if ($this->image_library == 'imagemagick' OR $this->image_library == 'netpbm') + if ($this->image_library === 'imagemagick' OR $this->image_library === 'netpbm') { $protocol = 'image_process_'.$this->image_library; return $this->$protocol('rotate'); } - if ($this->rotation_angle == 'hor' OR $this->rotation_angle == 'vrt') - { - return $this->image_mirror_gd(); - } - else - { - return $this->image_rotate_gd(); - } + return ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') + ? $this->image_mirror_gd() + : $this->image_rotate_gd(); } // -------------------------------------------------------------------- @@ -482,7 +462,7 @@ class CI_Image_lib { // Let's set up our values based on the action if ($action == 'crop') { - // Reassign the source width/height if cropping + // Reassign the source width/height if cropping $this->orig_width = $this->width; $this->orig_height = $this->height; @@ -506,13 +486,14 @@ class CI_Image_lib { return FALSE; } - // Create The Image - // - // old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" - // it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment - // below should that ever prove inaccurate. - // - // if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor') AND $v2_override == FALSE) + /* Create the image + * + * Old conditional which users report cause problems with shared GD libs who report themselves as "2.0 or greater" + * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment + * below should that ever prove inaccurate. + * + * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE) + */ if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) { $create = 'imagecreatetruecolor'; @@ -534,21 +515,17 @@ class CI_Image_lib { $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); - // Show the image + // Show the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($dst_img); } - else + elseif ( ! $this->image_save_gd($dst_img)) // Or save it { - // Or save it - if ( ! $this->image_save_gd($dst_img)) - { - return FALSE; - } + return FALSE; } - // Kill the file handles + // Kill the file handles imagedestroy($dst_img); imagedestroy($src_img); @@ -583,7 +560,7 @@ class CI_Image_lib { } // Execute the command - $cmd = $this->library_path." -quality ".$this->quality; + $cmd = $this->library_path.' -quality '.$this->quality; if ($action == 'crop') { @@ -591,15 +568,8 @@ class CI_Image_lib { } elseif ($action == 'rotate') { - switch ($this->rotation_angle) - { - case 'hor' : $angle = '-flop'; - break; - case 'vrt' : $angle = '-flip'; - break; - default : $angle = '-rotate '.$this->rotation_angle; - break; - } + $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') + ? '-flop' : '-rotate '.$this->rotation_angle; $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; } @@ -642,7 +612,7 @@ class CI_Image_lib { return FALSE; } - // Build the resizing command + // Build the resizing command switch ($this->image_type) { case 1 : @@ -702,7 +672,7 @@ class CI_Image_lib { // If you try manipulating the original it fails so // we have to rename the temp file. copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); - unlink ($this->dest_folder.'netpbm.tmp'); + unlink($this->dest_folder.'netpbm.tmp'); @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; @@ -717,7 +687,7 @@ class CI_Image_lib { */ public function image_rotate_gd() { - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -772,7 +742,7 @@ class CI_Image_lib { $width = $this->orig_width; $height = $this->orig_height; - if ($this->rotation_angle == 'hor') + if ($this->rotation_angle === 'hor') { for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) { @@ -839,7 +809,7 @@ class CI_Image_lib { */ public function watermark() { - return ($this->wm_type == 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); + return ($this->wm_type === 'overlay') ? $this->overlay_watermark() : $this->text_watermark(); } // -------------------------------------------------------------------- @@ -861,10 +831,10 @@ class CI_Image_lib { $this->get_image_properties(); // Fetch watermark image properties - $props = $this->get_image_properties($this->wm_overlay_path, TRUE); + $props = $this->get_image_properties($this->wm_overlay_path, TRUE); $wm_img_type = $props['image_type']; - $wm_width = $props['width']; - $wm_height = $props['height']; + $wm_width = $props['width']; + $wm_height = $props['height']; // Create two image resources $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); @@ -891,25 +861,23 @@ class CI_Image_lib { $y_axis = $this->wm_vrt_offset + $this->wm_padding; // Set the vertical position - switch ($this->wm_vrt_alignment) + if ($this->wm_vrt_alignment === 'M') { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height / 2) - ($wm_height / 2); - break; - case 'B': $y_axis += $this->orig_height - $wm_height; - break; + $y_axis += ($this->orig_height / 2) - ($wm_height / 2); + } + elseif ($this->wm_vrt_alignment === 'B') + { + $y_axis += $this->orig_height - $wm_height; } // Set the horizontal position - switch ($this->wm_hor_alignment) + if ($this->wm_hor_alignment === 'C') { - case 'L': - break; - case 'C': $x_axis += ($this->orig_width / 2) - ($wm_width / 2); - break; - case 'R': $x_axis += $this->orig_width - $wm_width; - break; + $x_axis += ($this->orig_width / 2) - ($wm_width / 2); + } + elseif ($this->wm_hor_alignment === 'R') + { + $x_axis += $this->orig_width - $wm_width; } // Build the finalized image @@ -935,12 +903,12 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // Output the image + // Output the image if ($this->dynamic_output == TRUE) { $this->image_display_gd($src_img); } - elseif ( ! $this->image_save_gd($src_img)) + elseif ( ! $this->image_save_gd($src_img)) // ... or save it { return FALSE; } @@ -977,7 +945,7 @@ class CI_Image_lib { // Reverse the vertical offset // When the image is positioned at the bottom // we don't want the vertical offset to push it - // further down. We want the reverse, so we'll + // further down. We want the reverse, so we'll // invert the offset. Note: The horizontal // offset flips itself automatically @@ -1011,49 +979,39 @@ class CI_Image_lib { $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - // Set verticle alignment if ($this->wm_use_drop_shadow == FALSE) $this->wm_shadow_distance = 0; $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); - switch ($this->wm_vrt_alignment) + // Set verticle alignment + if ($this->wm_vrt_alignment === 'M') { - case 'T': - break; - case 'M': $y_axis += ($this->orig_height/2)+($fontheight/2); - break; - case 'B': $y_axis += ($this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight/2)); - break; + $y_axis += ($this->orig_height / 2) + ($fontheight / 2); + } + elseif ($this->wm_vrt_alignment === 'B') + { + $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); } $x_shad = $x_axis + $this->wm_shadow_distance; $y_shad = $y_axis + $this->wm_shadow_distance; - // Set horizontal alignment - switch ($this->wm_hor_alignment) - { - case 'L': - break; - case 'R': - if ($this->wm_use_drop_shadow) - { - $x_shad += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - $x_axis += ($this->orig_width - $fontwidth*strlen($this->wm_text)); - } - break; - case 'C': - if ($this->wm_use_drop_shadow) - { - $x_shad += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - $x_axis += floor(($this->orig_width - $fontwidth*strlen($this->wm_text))/2); - } - break; - } - if ($this->wm_use_drop_shadow) { + // Set horizontal alignment + if ($this->wm_hor_alignment === 'R') + { + $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + } + elseif ($this->wm_hor_alignment === 'C') + { + $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + } + /* Set RGB values for text and shadow * * First character is #, so we don't really need it. @@ -1222,8 +1180,8 @@ class CI_Image_lib { */ public function image_display_gd($resource) { - header("Content-Disposition: filename={$this->source_image};"); - header("Content-Type: {$this->mime_type}"); + header('Content-Disposition: filename='.$this->source_image.';'); + header('Content-Type: '.$this->mime_type); header('Content-Transfer-Encoding: binary'); header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()).' GMT'); @@ -1351,15 +1309,15 @@ class CI_Image_lib { * Size calculator * * This function takes a known width x height and - * recalculates it to a new size. Only one + * recalculates it to a new size. Only one * new variable needs to be known * * $props = array( - * 'width' => $width, - * 'height' => $height, - * 'new_width' => 40, - * 'new_height' => '' - * ); + * 'width' => $width, + * 'height' => $height, + * 'new_width' => 40, + * 'new_height' => '' + * ); * * @param array * @return array @@ -1403,7 +1361,7 @@ class CI_Image_lib { * * This is a helper function that extracts the extension * from the source_image. This function lets us deal with - * source_images with multiple periods, like: my.cool.jpg + * source_images with multiple periods, like: my.cool.jpg * It returns an associative array with two elements: * $array['ext'] = '.jpg'; * $array['name'] = 'my.cool'; @@ -1498,7 +1456,7 @@ class CI_Image_lib { */ public function display_errors($open = '

', $close = '

') { - return (count($this->error_msg) > 0) ? $open . implode($close . $open, $this->error_msg) . $close : ''; + return (count($this->error_msg) > 0) ? $open.implode($close.$open, $this->error_msg).$close : ''; } } -- cgit v1.2.3-24-g4f1b From a3d19c4ac63c4af1c2b823b0962e6be79e89d186 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:29:29 +0200 Subject: Revert a space in the license agreement :) --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 065f479e8..5ea830fb1 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9826eabdd..86b77bf07 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 1b815532378bd444347d1bc741771e13108147b6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 16:06:03 +0300 Subject: Minor cleanup and style fixes in the Unit_test and Image_lib libraries --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 86b77bf07..1ab8b23e0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -251,7 +251,7 @@ class CI_Image_lib { } else { - if (strpos($this->new_image, '/') === FALSE AND strpos($this->new_image, '\\') === FALSE) + if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE) { $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); } @@ -1462,4 +1462,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b8e6285feff1b699a94ea56fd9c2067c3a60d3f5 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 26 Apr 2012 18:40:54 -0400 Subject: Fix Config.php and partially fix Image_lib.php --- system/libraries/Image_lib.php | 223 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 205 insertions(+), 18 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 1ab8b23e0..e90f325ae 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -36,41 +36,228 @@ */ class CI_Image_lib { - public $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2 + /** + * PHP extension/library to use for image manipulation + * Can be: imagemagick, netpbm, gd, gd2 + * + * @var string + */ + public $image_library = 'gd2'; + + /** + * Path to the graphic library (if applicable) + * + * @var string + */ public $library_path = ''; - public $dynamic_output = FALSE; // Whether to send to browser or write to disk + + /** + * Whether to send to browser or write to disk + * + * @var bool + */ + public $dynamic_output = FALSE; + + /** + * Path to original image + * + * @var string + */ public $source_image = ''; + + /** + * Path to the modified image + * + * @var string + */ public $new_image = ''; + + /** + * Image width + * + * @var int + */ public $width = ''; + + /** + * Image height + * + * @var int + */ public $height = ''; + + /** + * Quality percentage of new image + * + * @var int + */ public $quality = '90'; + + /** + * Whether to create a thumbnail + * + * @var bool + */ public $create_thumb = FALSE; + + /** + * String to add to thumbnail version of image + * + * @var string + */ public $thumb_marker = '_thumb'; - public $maintain_ratio = TRUE; // Whether to maintain aspect ratio when resizing or use hard values - public $master_dim = 'auto'; // auto, height, or width. Determines what to use as the master dimension + + /** + * Whether to maintain aspect ratio when resizing or use hard values + * + * @var bool + */ + public $maintain_ratio = TRUE; + + /** + * auto, height, or width. Determines what to use as the master dimension + * + * @var string + */ + public $master_dim = 'auto'; + + /** + * Angle at to rotate image + * + * @var string + */ public $rotation_angle = ''; + + /** + * X Coordinate for manipulation of the current image + * + * @var int + */ public $x_axis = ''; + + /** + * Y Coordinate for manipulation of the current image + * + * @var int + */ public $y_axis = ''; + // -------------------------------------------------------------------------- // Watermark Vars - public $wm_text = ''; // Watermark text if graphic is not used - public $wm_type = 'text'; // Type of watermarking. Options: text/overlay + // -------------------------------------------------------------------------- + + /** + * Watermark text if graphic is not used + * + * @var string + */ + public $wm_text = ''; + + /** + * Type of watermarking. Options: text/overlay + * + * @var string + */ + public $wm_type = 'text'; + + /** + * @var int + */ public $wm_x_transp = 4; + + /** + * @var int + */ public $wm_y_transp = 4; - public $wm_overlay_path = ''; // Watermark image path - public $wm_font_path = ''; // TT font - public $wm_font_size = 17; // Font size (different versions of GD will either use points or pixels) - public $wm_vrt_alignment = 'B'; // Vertical alignment: T M B - public $wm_hor_alignment = 'C'; // Horizontal alignment: L R C - public $wm_padding = 0; // Padding around text - public $wm_hor_offset = 0; // Lets you push text to the right - public $wm_vrt_offset = 0; // Lets you push text down - protected $wm_font_color = '#ffffff'; // Text color - protected $wm_shadow_color = ''; // Dropshadow color - public $wm_shadow_distance = 2; // Dropshadow distance - public $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image + + /** + * Watermark image path + * + * @var string + */ + public $wm_overlay_path = ''; + + /** + * TT font + * + * @var string + */ + public $wm_font_path = ''; + + /** + * Font size (different versions of GD will either use points or pixels) + * + * @var int + */ + public $wm_font_size = 17; + + /** + * Vertical alignment: T M B + * + * @var string + */ + public $wm_vrt_alignment = 'B'; + + /** + * Horizontal alignment: L R C + * + * @var string + */ + public $wm_hor_alignment = 'C'; + + /** + * Padding around text + * + * @var int + */ + public $wm_padding = 0; + + /** + * Lets you push text to the right + * + * @var int + */ + public $wm_hor_offset = 0; + + /** + * Lets you push text down + * + * @var int + */ + public $wm_vrt_offset = 0; + + /** + * Text color + * + * @var string + */ + protected $wm_font_color = '#ffffff'; + + /** + * Dropshadow color + * + * @var string + */ + protected $wm_shadow_color = ''; + + /** + * Dropshadow distance + * + * @var int + */ + public $wm_shadow_distance = 2; + + /** + * Image opacity: 1 - 100 Only works with image + * + * @var int + */ + public $wm_opacity = 50; + // -------------------------------------------------------------------------- // Private Vars + // -------------------------------------------------------------------------- + public $source_folder = ''; public $dest_folder = ''; public $mime_type = ''; -- cgit v1.2.3-24-g4f1b From b82bc3a016ce01dfeb993da5918853625a40af86 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 09:12:58 -0400 Subject: Fix Cache, Image_lib and Log libraries --- system/libraries/Image_lib.php | 96 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index e90f325ae..24695049c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -161,11 +161,15 @@ class CI_Image_lib { public $wm_type = 'text'; /** + * Default transparency for watermark + * * @var int */ public $wm_x_transp = 4; /** + * Default transparency for watermark + * * @var int */ public $wm_y_transp = 4; @@ -258,21 +262,109 @@ class CI_Image_lib { // Private Vars // -------------------------------------------------------------------------- + /** + * Source image folder + * + * @var string + */ public $source_folder = ''; + + /** + * Destination image folder + * + * @var string + */ public $dest_folder = ''; + + /** + * Image mime-type + * + * @var string + */ public $mime_type = ''; + + /** + * Original image width + * + * @var int + */ public $orig_width = ''; + + /** + * Original image height + * + * @var int + */ public $orig_height = ''; + + /** + * Image format + * + * @var string + */ public $image_type = ''; + + /** + * Size of current image + * + * @var string + */ public $size_str = ''; + + /** + * Full path to source image + * + * @var string + */ public $full_src_path = ''; + + /** + * Full path to destination image + * + * @var string + */ public $full_dst_path = ''; + + /** + * Name of function to create image + * + * @var string + */ public $create_fnc = 'imagecreatetruecolor'; + + /** + * Name of function to copy image + * + * @var string + */ public $copy_fnc = 'imagecopyresampled'; + + /** + * Error messages + * + * @var array + */ public $error_msg = array(); + + /** + * Whether to have a drop shadow on watermark + * + * @var bool + */ protected $wm_use_drop_shadow = FALSE; + + /** + * Whether to use truetype fonts + * + * @var bool + */ public $wm_use_truetype = FALSE; + /** + * Initialize Image Library + * + * @param array $props + */ public function __construct($props = array()) { if (count($props) > 0) @@ -991,7 +1083,6 @@ class CI_Image_lib { * This is a wrapper function that chooses the type * of watermarking based on the specified preference. * - * @param string * @return bool */ public function watermark() @@ -1247,6 +1338,7 @@ class CI_Image_lib { * based on the type of image being processed * * @param string + * @param string * @return resource */ public function image_create_gd($path = '', $image_type = '') @@ -1448,6 +1540,7 @@ class CI_Image_lib { * A helper function that gets info about the file * * @param string + * @param bool * @return mixed */ public function get_image_properties($path = '', $return = FALSE) @@ -1639,6 +1732,7 @@ class CI_Image_lib { * Show error messages * * @param string + * @param string * @return string */ public function display_errors($open = '

', $close = '

') -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Image_lib.php | 252 +++++++++++++++++++++-------------------- 1 file changed, 127 insertions(+), 125 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 24695049c..0cb189445 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -38,321 +38,321 @@ class CI_Image_lib { /** * PHP extension/library to use for image manipulation - * Can be: imagemagick, netpbm, gd, gd2 + * Can be: imagemagick, netpbm, gd, gd2 * * @var string */ public $image_library = 'gd2'; - + /** * Path to the graphic library (if applicable) * * @var string */ public $library_path = ''; - + /** * Whether to send to browser or write to disk * * @var bool */ public $dynamic_output = FALSE; - + /** * Path to original image * * @var string */ public $source_image = ''; - + /** * Path to the modified image * * @var string */ - public $new_image = ''; - + public $new_image = ''; + /** * Image width * * @var int */ - public $width = ''; - + public $width = ''; + /** * Image height * * @var int */ - public $height = ''; - + public $height = ''; + /** * Quality percentage of new image * * @var int */ - public $quality = '90'; - + public $quality = 90; + /** * Whether to create a thumbnail * * @var bool */ public $create_thumb = FALSE; - + /** * String to add to thumbnail version of image * * @var string */ public $thumb_marker = '_thumb'; - + /** * Whether to maintain aspect ratio when resizing or use hard values * * @var bool */ public $maintain_ratio = TRUE; - + /** * auto, height, or width. Determines what to use as the master dimension * * @var string */ - public $master_dim = 'auto'; - + public $master_dim = 'auto'; + /** * Angle at to rotate image * * @var string */ public $rotation_angle = ''; - + /** * X Coordinate for manipulation of the current image * * @var int */ - public $x_axis = ''; - + public $x_axis = ''; + /** * Y Coordinate for manipulation of the current image * * @var int */ - public $y_axis = ''; + public $y_axis = ''; // -------------------------------------------------------------------------- // Watermark Vars // -------------------------------------------------------------------------- - + /** * Watermark text if graphic is not used * * @var string */ public $wm_text = ''; - + /** * Type of watermarking. Options: text/overlay * * @var string */ public $wm_type = 'text'; - + /** * Default transparency for watermark - * + * * @var int */ public $wm_x_transp = 4; - + /** * Default transparency for watermark * * @var int */ public $wm_y_transp = 4; - + /** * Watermark image path - * + * * @var string */ - public $wm_overlay_path = ''; - + public $wm_overlay_path = ''; + /** * TT font * * @var string */ public $wm_font_path = ''; - + /** * Font size (different versions of GD will either use points or pixels) * * @var int */ public $wm_font_size = 17; - + /** * Vertical alignment: T M B * * @var string */ public $wm_vrt_alignment = 'B'; - + /** * Horizontal alignment: L R C * * @var string */ public $wm_hor_alignment = 'C'; - + /** * Padding around text * * @var int */ public $wm_padding = 0; - + /** * Lets you push text to the right * * @var int */ public $wm_hor_offset = 0; - + /** * Lets you push text down * * @var int */ public $wm_vrt_offset = 0; - + /** * Text color * * @var string */ - protected $wm_font_color = '#ffffff'; - + protected $wm_font_color = '#ffffff'; + /** * Dropshadow color * * @var string */ - protected $wm_shadow_color = ''; - + protected $wm_shadow_color = ''; + /** * Dropshadow distance * * @var int */ public $wm_shadow_distance = 2; - + /** * Image opacity: 1 - 100 Only works with image * * @var int */ - public $wm_opacity = 50; + public $wm_opacity = 50; // -------------------------------------------------------------------------- // Private Vars // -------------------------------------------------------------------------- - + /** * Source image folder * * @var string */ public $source_folder = ''; - + /** * Destination image folder * * @var string */ public $dest_folder = ''; - + /** * Image mime-type * * @var string */ - public $mime_type = ''; - + public $mime_type = ''; + /** - * Original image width + * Original image width * * @var int */ - public $orig_width = ''; - + public $orig_width = ''; + /** * Original image height * * @var int */ public $orig_height = ''; - + /** * Image format - * + * * @var string */ - public $image_type = ''; - + public $image_type = ''; + /** * Size of current image * * @var string */ - public $size_str = ''; - + public $size_str = ''; + /** * Full path to source image * * @var string */ public $full_src_path = ''; - + /** * Full path to destination image * * @var string */ public $full_dst_path = ''; - + /** * Name of function to create image * * @var string */ - public $create_fnc = 'imagecreatetruecolor'; - + public $create_fnc = 'imagecreatetruecolor'; + /** * Name of function to copy image * * @var string */ - public $copy_fnc = 'imagecopyresampled'; - + public $copy_fnc = 'imagecopyresampled'; + /** * Error messages * * @var array */ - public $error_msg = array(); - + public $error_msg = array(); + /** * Whether to have a drop shadow on watermark * * @var bool */ protected $wm_use_drop_shadow = FALSE; - + /** * Whether to use truetype fonts * @@ -364,6 +364,7 @@ class CI_Image_lib { * Initialize Image Library * * @param array $props + * @return void */ public function __construct($props = array()) { @@ -395,7 +396,7 @@ class CI_Image_lib { $this->image_library = 'gd2'; $this->dynamic_output = FALSE; - $this->quality = '90'; + $this->quality = 90; $this->create_thumb = FALSE; $this->thumb_marker = '_thumb'; $this->maintain_ratio = TRUE; @@ -895,16 +896,16 @@ class CI_Image_lib { switch ($this->image_type) { case 1 : - $cmd_in = 'giftopnm'; - $cmd_out = 'ppmtogif'; + $cmd_in = 'giftopnm'; + $cmd_out = 'ppmtogif'; break; case 2 : - $cmd_in = 'jpegtopnm'; - $cmd_out = 'ppmtojpeg'; + $cmd_in = 'jpegtopnm'; + $cmd_out = 'ppmtojpeg'; break; case 3 : - $cmd_in = 'pngtopnm'; - $cmd_out = 'ppmtopng'; + $cmd_in = 'pngtopnm'; + $cmd_out = 'ppmtopng'; break; } @@ -916,15 +917,15 @@ class CI_Image_lib { { switch ($this->rotation_angle) { - case 90 : $angle = 'r270'; + case 90: $angle = 'r270'; break; - case 180 : $angle = 'r180'; + case 180: $angle = 'r180'; break; - case 270 : $angle = 'r90'; + case 270: $angle = 'r90'; break; - case 'vrt' : $angle = 'tb'; + case 'vrt': $angle = 'tb'; break; - case 'hor' : $angle = 'lr'; + case 'hor': $angle = 'lr'; break; } @@ -1401,49 +1402,49 @@ class CI_Image_lib { { switch ($this->image_type) { - case 1 : - if ( ! function_exists('imagegif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } + case 1: + if ( ! function_exists('imagegif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } - if ( ! @imagegif($resource, $this->full_dst_path)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - case 2 : - if ( ! function_exists('imagejpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } + if ( ! @imagegif($resource, $this->full_dst_path)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } + break; + case 2: + if ( ! function_exists('imagejpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } - if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - case 3 : - if ( ! function_exists('imagepng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } + if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } + break; + case 3: + if ( ! function_exists('imagepng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } - if ( ! @imagepng($resource, $this->full_dst_path)) - { - $this->set_error('imglib_save_failed'); - return FALSE; - } - break; - default : - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; - break; + if ( ! @imagepng($resource, $this->full_dst_path)) + { + $this->set_error('imglib_save_failed'); + return FALSE; + } + break; + default: + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; + break; } return TRUE; @@ -1466,13 +1467,13 @@ class CI_Image_lib { switch ($this->image_type) { - case 1 : imagegif($resource); + case 1 : imagegif($resource); break; - case 2 : imagejpeg($resource, '', $this->quality); + case 2 : imagejpeg($resource, '', $this->quality); break; - case 3 : imagepng($resource); + case 3 : imagepng($resource); break; - default : echo 'Unable to display the image'; + default: echo 'Unable to display the image'; break; } } @@ -1613,8 +1614,10 @@ class CI_Image_lib { foreach ($allowed as $item) { - if ( ! isset($vals[$item]) OR $vals[$item] == '') + if (empty($vals[$item])) + { $vals[$item] = 0; + } } if ($vals['width'] == 0 OR $vals['height'] == 0) @@ -1712,7 +1715,6 @@ class CI_Image_lib { { foreach ($msg as $val) { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); -- cgit v1.2.3-24-g4f1b From d261b1e89c3d4d5191036d5a5660ef6764e593a0 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:16 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/libraries --- system/libraries/Image_lib.php | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0cb189445..c3973a02f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -466,7 +466,7 @@ class CI_Image_lib { } // Is there a source image? If not, there's no reason to continue - if ($this->source_image == '') + if ($this->source_image === '') { $this->set_error('imglib_source_image_required'); return FALSE; @@ -519,7 +519,7 @@ class CI_Image_lib { * it means we are altering the original. We'll * set the destination filename and path accordingly. */ - if ($this->new_image == '') + if ($this->new_image === '') { $this->dest_image = $this->source_image; $this->dest_folder = $this->source_folder; @@ -562,7 +562,7 @@ class CI_Image_lib { * We'll also split the destination image name * so we can insert the thumbnail marker if needed. */ - if ($this->create_thumb === FALSE OR $this->thumb_marker == '') + if ($this->create_thumb === FALSE OR $this->thumb_marker === '') { $this->thumb_marker = ''; } @@ -581,7 +581,7 @@ class CI_Image_lib { * might not be in correct proportion with the source * image's width/height. We'll recalculate it here. */ - if ($this->maintain_ratio === TRUE && ($this->width != 0 OR $this->height != 0)) + if ($this->maintain_ratio === TRUE && ($this->width !== 0 OR $this->height !== 0)) { $this->image_reproportion(); } @@ -591,12 +591,12 @@ class CI_Image_lib { * If the destination width/height was not submitted we * will use the values from the actual file */ - if ($this->width == '') + if ($this->width === '') { $this->width = $this->orig_width; } - if ($this->height == '') + if ($this->height === '') { $this->height = $this->orig_height; } @@ -604,31 +604,31 @@ class CI_Image_lib { // Set the quality $this->quality = trim(str_replace('%', '', $this->quality)); - if ($this->quality == '' OR $this->quality == 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) + if ($this->quality === '' OR $this->quality === 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) { $this->quality = 90; } // Set the x/y coordinates - $this->x_axis = ($this->x_axis == '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis == '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; + $this->x_axis = ($this->x_axis === '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; + $this->y_axis = ($this->y_axis === '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; // Watermark-related Stuff... - if ($this->wm_overlay_path != '') + if ($this->wm_overlay_path !== '') { $this->wm_overlay_path = str_replace('\\', '/', realpath($this->wm_overlay_path)); } - if ($this->wm_shadow_color != '') + if ($this->wm_shadow_color !== '') { $this->wm_use_drop_shadow = TRUE; } - elseif ($this->wm_use_drop_shadow == TRUE && $this->wm_shadow_color == '') + elseif ($this->wm_use_drop_shadow === TRUE && $this->wm_shadow_color === '') { $this->wm_use_drop_shadow = FALSE; } - if ($this->wm_font_path != '') + if ($this->wm_font_path !== '') { $this->wm_use_truetype = TRUE; } @@ -683,14 +683,14 @@ class CI_Image_lib { // Allowed rotation values $degs = array(90, 180, 270, 'vrt', 'hor'); - if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs)) + if ($this->rotation_angle === '' OR ! in_array($this->rotation_angle, $degs)) { $this->set_error('imglib_rotation_angle_required'); return FALSE; } // Reassign the width and height - if ($this->rotation_angle == 90 OR $this->rotation_angle == 270) + if ($this->rotation_angle === 90 OR $this->rotation_angle === 270) { $this->width = $this->orig_height; $this->height = $this->orig_width; @@ -729,9 +729,9 @@ class CI_Image_lib { // If the target width/height match the source, AND if the new file name is not equal to the old file name // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off. - if ($this->dynamic_output === FALSE && $this->orig_width == $this->width && $this->orig_height == $this->height) + if ($this->dynamic_output === FALSE && $this->orig_width === $this->width && $this->orig_height === $this->height) { - if ($this->source_image != $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) + if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) { @chmod($this->full_dst_path, FILE_WRITE_MODE); } @@ -740,7 +740,7 @@ class CI_Image_lib { } // Let's set up our values based on the action - if ($action == 'crop') + if ($action === 'crop') { // Reassign the source width/height if cropping $this->orig_width = $this->width; @@ -750,7 +750,7 @@ class CI_Image_lib { if ($this->gd_version() !== FALSE) { $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version == 2) ? TRUE : FALSE; + $v2_override = ($gd_version === 2) ? TRUE : FALSE; } } else @@ -772,7 +772,7 @@ class CI_Image_lib { * it appears that this is no longer the issue that it was in 2004, so we've removed it, retaining it in the comment * below should that ever prove inaccurate. * - * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override == FALSE) + * if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor') && $v2_override === FALSE) */ if ($this->image_library === 'gd2' && function_exists('imagecreatetruecolor')) { @@ -787,7 +787,7 @@ class CI_Image_lib { $dst_img = $create($this->width, $this->height); - if ($this->image_type == 3) // png we can actually preserve transparency + if ($this->image_type === 3) // png we can actually preserve transparency { imagealphablending($dst_img, FALSE); imagesavealpha($dst_img, TRUE); @@ -796,7 +796,7 @@ class CI_Image_lib { $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height); // Show the image - if ($this->dynamic_output == TRUE) + if ($this->dynamic_output === TRUE) { $this->image_display_gd($dst_img); } @@ -828,7 +828,7 @@ class CI_Image_lib { public function image_process_imagemagick($action = 'resize') { // Do we have a vaild library path? - if ($this->library_path == '') + if ($this->library_path === '') { $this->set_error('imglib_libpath_invalid'); return FALSE; @@ -842,11 +842,11 @@ class CI_Image_lib { // Execute the command $cmd = $this->library_path.' -quality '.$this->quality; - if ($action == 'crop') + if ($action === 'crop') { $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1'; } - elseif ($action == 'rotate') + elseif ($action === 'rotate') { $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') ? '-flop' : '-rotate '.$this->rotation_angle; @@ -886,7 +886,7 @@ class CI_Image_lib { */ public function image_process_netpbm($action = 'resize') { - if ($this->library_path == '') + if ($this->library_path === '') { $this->set_error('imglib_libpath_invalid'); return FALSE; @@ -909,11 +909,11 @@ class CI_Image_lib { break; } - if ($action == 'crop') + if ($action === 'crop') { $cmd_inner = 'pnmcut -left '.$this->x_axis.' -top '.$this->y_axis.' -width '.$this->width.' -height '.$this->height; } - elseif ($action == 'rotate') + elseif ($action === 'rotate') { switch ($this->rotation_angle) { @@ -984,7 +984,7 @@ class CI_Image_lib { $dst_img = imagerotate($src_img, $this->rotation_angle, $white); // Show the image - if ($this->dynamic_output == TRUE) + if ($this->dynamic_output === TRUE) { $this->image_display_gd($dst_img); } @@ -1058,7 +1058,7 @@ class CI_Image_lib { } // Show the image - if ($this->dynamic_output == TRUE) + if ($this->dynamic_output === TRUE) { $this->image_display_gd($src_img); } @@ -1129,10 +1129,10 @@ class CI_Image_lib { $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); - if ($this->wm_vrt_alignment == 'B') + if ($this->wm_vrt_alignment === 'B') $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - if ($this->wm_hor_alignment == 'R') + if ($this->wm_hor_alignment === 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; // Set the base x and y axis values @@ -1160,7 +1160,7 @@ class CI_Image_lib { } // Build the finalized image - if ($wm_img_type == 3 && function_exists('imagealphablending')) + if ($wm_img_type === 3 && function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); } @@ -1183,7 +1183,7 @@ class CI_Image_lib { } // Output the image - if ($this->dynamic_output == TRUE) + if ($this->dynamic_output === TRUE) { $this->image_display_gd($src_img); } @@ -1212,7 +1212,7 @@ class CI_Image_lib { return FALSE; } - if ($this->wm_use_truetype == TRUE && ! file_exists($this->wm_font_path)) + if ($this->wm_use_truetype === TRUE && ! file_exists($this->wm_font_path)) { $this->set_error('imglib_missing_font'); return FALSE; @@ -1228,18 +1228,18 @@ class CI_Image_lib { // invert the offset. Note: The horizontal // offset flips itself automatically - if ($this->wm_vrt_alignment == 'B') + if ($this->wm_vrt_alignment === 'B') $this->wm_vrt_offset = $this->wm_vrt_offset * -1; - if ($this->wm_hor_alignment == 'R') + if ($this->wm_hor_alignment === 'R') $this->wm_hor_offset = $this->wm_hor_offset * -1; // Set font width and height // These are calculated differently depending on // whether we are using the true type font or not - if ($this->wm_use_truetype == TRUE) + if ($this->wm_use_truetype === TRUE) { - if ($this->wm_font_size == '') + if ($this->wm_font_size === '') { $this->wm_font_size = 17; } @@ -1258,7 +1258,7 @@ class CI_Image_lib { $x_axis = $this->wm_hor_offset + $this->wm_padding; $y_axis = $this->wm_vrt_offset + $this->wm_padding; - if ($this->wm_use_drop_shadow == FALSE) + if ($this->wm_use_drop_shadow === FALSE) $this->wm_shadow_distance = 0; $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); @@ -1316,7 +1316,7 @@ class CI_Image_lib { } // Output the final image - if ($this->dynamic_output == TRUE) + if ($this->dynamic_output === TRUE) { $this->image_display_gd($src_img); } @@ -1344,10 +1344,10 @@ class CI_Image_lib { */ public function image_create_gd($path = '', $image_type = '') { - if ($path == '') + if ($path === '') $path = $this->full_src_path; - if ($image_type == '') + if ($image_type === '') $image_type = $this->image_type; @@ -1494,7 +1494,7 @@ class CI_Image_lib { */ public function image_reproportion() { - if (($this->width == 0 && $this->height == 0) OR $this->orig_width == 0 OR $this->orig_height == 0 + if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0 OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height)) OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height)) { @@ -1549,7 +1549,7 @@ class CI_Image_lib { // For now we require GD but we should // find a way to determine this using IM or NetPBM - if ($path == '') + if ($path === '') { $path = $this->full_src_path; } @@ -1564,7 +1564,7 @@ class CI_Image_lib { $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; - if ($return == TRUE) + if ($return === TRUE) { return array( 'width' => $vals[0], @@ -1620,16 +1620,16 @@ class CI_Image_lib { } } - if ($vals['width'] == 0 OR $vals['height'] == 0) + if ($vals['width'] === 0 OR $vals['height'] === 0) { return $vals; } - if ($vals['new_width'] == 0) + if ($vals['new_width'] === 0) { $vals['new_width'] = ceil($vals['width']*$vals['new_height']/$vals['height']); } - elseif ($vals['new_height'] == 0) + elseif ($vals['new_height'] === 0) { $vals['new_height'] = ceil($vals['new_width']*$vals['height']/$vals['width']); } @@ -1715,14 +1715,14 @@ class CI_Image_lib { { foreach ($msg as $val) { - $msg = ($CI->lang->line($val) == FALSE) ? $val : $CI->lang->line($val); + $msg = ($CI->lang->line($val) === FALSE) ? $val : $CI->lang->line($val); $this->error_msg[] = $msg; log_message('error', $msg); } } else { - $msg = ($CI->lang->line($msg) == FALSE) ? $msg : $CI->lang->line($msg); + $msg = ($CI->lang->line($msg) === FALSE) ? $msg : $CI->lang->line($msg); $this->error_msg[] = $msg; log_message('error', $msg); } -- cgit v1.2.3-24-g4f1b From 5036c9caabb12f90b9533d7fb417610e02a652ff Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 15:34:56 +0300 Subject: Revert/optimize some changes from 773ccc318f2769c9b7579630569b5d8ba47b114b and d261b1e89c3d4d5191036d5a5660ef6764e593a0 --- system/libraries/Image_lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c3973a02f..4735dfd08 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -610,8 +610,8 @@ class CI_Image_lib { } // Set the x/y coordinates - $this->x_axis = ($this->x_axis === '' OR ! preg_match('/^[0-9]+$/', $this->x_axis)) ? 0 : $this->x_axis; - $this->y_axis = ($this->y_axis === '' OR ! preg_match('/^[0-9]+$/', $this->y_axis)) ? 0 : $this->y_axis; + is_numeric($this->x_axis) OR $this->x_axis = 0; + is_numeric($this->y_axis) OR $this->y_axis = 0; // Watermark-related Stuff... if ($this->wm_overlay_path !== '') @@ -750,7 +750,7 @@ class CI_Image_lib { if ($this->gd_version() !== FALSE) { $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version === 2) ? TRUE : FALSE; + $v2_override = ($gd_version === 2); } } else -- cgit v1.2.3-24-g4f1b From bb531d6284e3a936e8e2184104edd9a665c5c363 Mon Sep 17 00:00:00 2001 From: Omar Date: Fri, 29 Jun 2012 10:48:28 -0300 Subject: Fixing imagemagick maintain ratio not implemented --- system/libraries/Image_lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4735dfd08..ebd214ef0 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -855,7 +855,10 @@ class CI_Image_lib { } else // Resize { - $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + if($this->maintain_ratio) + $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + else + $cmd .= " -resize ".$this->width."x".$this->height."\\! \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; } $retval = 1; -- cgit v1.2.3-24-g4f1b From 24063af4005804e271ac04fecca4a410a0a7b269 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 2 Jul 2012 13:50:17 -0300 Subject: Fixed code styling --- system/libraries/Image_lib.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ebd214ef0..899b995d4 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -855,10 +855,14 @@ class CI_Image_lib { } else // Resize { - if($this->maintain_ratio) - $cmd .= " -resize ".$this->width."x".$this->height." \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + if($this->maintain_ratio === TRUE) + { + $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + } else - $cmd .= " -resize ".$this->width."x".$this->height."\\! \"$this->full_src_path\" \"$this->full_dst_path\" 2>&1"; + { + $cmd .= ' -resize '.$this->width.'x'.$this->height.'\! "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + } } $retval = 1; -- cgit v1.2.3-24-g4f1b From 99ae226607fff411bae3b69475bd1b0e3981d563 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 15:14:30 +0300 Subject: Add PNG transparency support in CI_Image_lib::text_watermark() (originally from pull #1317, partially fixes #1139) --- system/libraries/Image_lib.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 899b995d4..ef4187847 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1320,6 +1320,13 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } + + // We can preserve transparency for PNG images + if ($this->image_type === 3) + { + imagealphablending($src_img, FALSE); + imagesavealpha($src_img, TRUE); + } } // Output the final image -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Image_lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ef4187847..3b453be47 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1,4 +1,4 @@ - Date: Wed, 7 Nov 2012 14:23:29 +0200 Subject: Added function_usable() to common functions It is now used to check whether dangerous functions like eval() and exec() are available. It appears that the Suhosin extension (which is becoming popular) terminates script execution instead of returning e.g. FALSE when it has a function blacklisted. function_exists() checks are insufficient and our only option is to check the ini settings here. Filed an issue here: https://github.com/stefanesser/suhosin/issues/18 ... hopefully we'll be able to deal with this in a more elegant way in the future. (this commit supersedes PR #1809) --- system/libraries/Image_lib.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 3b453be47..9379e3ec8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -867,7 +867,11 @@ class CI_Image_lib { } $retval = 1; - @exec($cmd, $output, $retval); + // exec() might be disabled + if (function_usable('exec')) + { + @exec($cmd, $output, $retval); + } // Did it work? if ($retval > 0) @@ -947,7 +951,11 @@ class CI_Image_lib { $cmd = $this->library_path.$cmd_in.' '.$this->full_src_path.' | '.$cmd_inner.' | '.$cmd_out.' > '.$this->dest_folder.'netpbm.tmp'; $retval = 1; - @exec($cmd, $output, $retval); + // exec() might be disabled + if (function_usable('exec')) + { + @exec($cmd, $output, $retval); + } // Did it work? if ($retval > 0) @@ -959,7 +967,7 @@ class CI_Image_lib { // With NetPBM we have to create a temporary image. // If you try manipulating the original it fails so // we have to rename the temp file. - copy ($this->dest_folder.'netpbm.tmp', $this->full_dst_path); + copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink($this->dest_folder.'netpbm.tmp'); @chmod($this->full_dst_path, FILE_WRITE_MODE); -- cgit v1.2.3-24-g4f1b From 7a7ad782b2f125622509a77c5a6f94ad4ae0f93c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Nov 2012 17:21:01 +0200 Subject: Some micro-optimizations --- system/libraries/Image_lib.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9379e3ec8..7f937f99b 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -605,7 +605,7 @@ class CI_Image_lib { // Set the quality $this->quality = trim(str_replace('%', '', $this->quality)); - if ($this->quality === '' OR $this->quality === 0 OR ! preg_match('/^[0-9]+$/', $this->quality)) + if ($this->quality === '' OR $this->quality === 0 OR ! ctype_digit($this->quality)) { $this->quality = 90; } @@ -1277,8 +1277,8 @@ class CI_Image_lib { if ($this->wm_use_drop_shadow === FALSE) $this->wm_shadow_distance = 0; - $this->wm_vrt_alignment = strtoupper(substr($this->wm_vrt_alignment, 0, 1)); - $this->wm_hor_alignment = strtoupper(substr($this->wm_hor_alignment, 0, 1)); + $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); + $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); // Set verticle alignment if ($this->wm_vrt_alignment === 'M') @@ -1518,13 +1518,13 @@ class CI_Image_lib { public function image_reproportion() { if (($this->width === 0 && $this->height === 0) OR $this->orig_width === 0 OR $this->orig_height === 0 - OR ( ! preg_match('/^[0-9]+$/', $this->width) && ! preg_match('/^[0-9]+$/', $this->height)) - OR ! preg_match('/^[0-9]+$/', $this->orig_width) OR ! preg_match('/^[0-9]+$/', $this->orig_height)) + OR ( ! ctype_digit((string) $this->width) && ! ctype_digit((string) $this->height)) + OR ! ctype_digit((string) $this->orig_width) OR ! ctype_digit((string) $this->orig_height)) { return; } - // Sanitize so we don't call preg_match() anymore + // Sanitize $this->width = (int) $this->width; $this->height = (int) $this->height; -- cgit v1.2.3-24-g4f1b From 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Dec 2012 14:37:47 +0200 Subject: [ci skip] Cleaned some spaces --- system/libraries/Image_lib.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 7f937f99b..46a9c120f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1373,7 +1373,6 @@ class CI_Image_lib { if ($image_type === '') $image_type = $this->image_type; - switch ($image_type) { case 1 : -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 46a9c120f..54a134f50 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 9cc707b8a5c726b7f2aa21b026dbf491a75e06c4 Mon Sep 17 00:00:00 2001 From: Ted Wood Date: Tue, 8 Jan 2013 19:41:45 -0800 Subject: fix imagejpeg() parameter, should be NULL instead of empty string --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 54a134f50..6d5493696 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1491,7 +1491,7 @@ class CI_Image_lib { { case 1 : imagegif($resource); break; - case 2 : imagejpeg($resource, '', $this->quality); + case 2 : imagejpeg($resource, NULL, $this->quality); break; case 3 : imagepng($resource); break; -- cgit v1.2.3-24-g4f1b From 16c6d7e8ab6b161d11c0e8dbca7dbbef58b49138 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 26 Jan 2013 17:21:29 +0100 Subject: Fix a code comment in Image_lib constant FILE_WRITE_MODE contains octal 0666 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 6d5493696..0cec43fc4 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -810,7 +810,7 @@ class CI_Image_lib { imagedestroy($dst_img); imagedestroy($src_img); - // Set the file to 777 + // Set the file to 666 @chmod($this->full_dst_path, FILE_WRITE_MODE); return TRUE; -- cgit v1.2.3-24-g4f1b From 5cb5c0a4354518ac1a8c5b71971d7a7232c33480 Mon Sep 17 00:00:00 2001 From: Sam Doidge Date: Wed, 13 Mar 2013 01:28:06 +0000 Subject: adding thumb_marker to image_lib->clear() --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 0cec43fc4..7f01ac028 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -388,7 +388,7 @@ class CI_Image_lib { */ public function clear() { - $props = array('library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); + $props = array('thumb_marker', 'library_path', 'source_image', 'new_image', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'wm_text', 'wm_overlay_path', 'wm_font_path', 'wm_shadow_color', 'source_folder', 'dest_folder', 'mime_type', 'orig_width', 'orig_height', 'image_type', 'size_str', 'full_src_path', 'full_dst_path'); foreach ($props as $val) { @@ -1767,4 +1767,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file +/* Location: ./system/libraries/Image_lib.php */ -- cgit v1.2.3-24-g4f1b From 7ee2034cabf965c68861b68093f126befbf26727 Mon Sep 17 00:00:00 2001 From: Sam Doidge Date: Wed, 13 Mar 2013 04:43:55 +0000 Subject: removing linebreak --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 7f01ac028..b6a11a3a5 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1767,4 +1767,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e52fc267a93fd3627951ddc7c5109b573a871727 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 11 Feb 2014 13:27:01 +0200 Subject: Fix issue #43 --- system/libraries/Image_lib.php | 71 +++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index b6a11a3a5..bb0ea7b50 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1245,22 +1245,37 @@ class CI_Image_lib { // offset flips itself automatically if ($this->wm_vrt_alignment === 'B') + { $this->wm_vrt_offset = $this->wm_vrt_offset * -1; + } if ($this->wm_hor_alignment === 'R') + { $this->wm_hor_offset = $this->wm_hor_offset * -1; + } // Set font width and height // These are calculated differently depending on // whether we are using the true type font or not if ($this->wm_use_truetype === TRUE) { - if ($this->wm_font_size === '') + if (empty($this->wm_font_size)) { $this->wm_font_size = 17; } - $fontwidth = $this->wm_font_size-($this->wm_font_size/4); + if (function_exists('imagettfbbox')) + { + $temp = imagettfbbox($this->wm_font_size, 0, $this->wm_font_path, $this->wm_text); + $temp = $temp[2] - $temp[0]; + + $fontwidth = $temp / strlen($this->wm_text); + } + else + { + $fontwidth = $this->wm_font_size - ($this->wm_font_size / 4); + } + $fontheight = $this->wm_font_size; $this->wm_vrt_offset += $this->wm_font_size; } @@ -1368,45 +1383,45 @@ class CI_Image_lib { public function image_create_gd($path = '', $image_type = '') { if ($path === '') + { $path = $this->full_src_path; + } if ($image_type === '') + { $image_type = $this->image_type; + } switch ($image_type) { - case 1 : - if ( ! function_exists('imagecreatefromgif')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); - return FALSE; - } + case 1 : + if ( ! function_exists('imagecreatefromgif')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); + return FALSE; + } - return imagecreatefromgif($path); - break; + return imagecreatefromgif($path); case 2 : - if ( ! function_exists('imagecreatefromjpeg')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); - return FALSE; - } + if ( ! function_exists('imagecreatefromjpeg')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); + return FALSE; + } - return imagecreatefromjpeg($path); - break; + return imagecreatefromjpeg($path); case 3 : - if ( ! function_exists('imagecreatefrompng')) - { - $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); - return FALSE; - } - - return imagecreatefrompng($path); - break; + if ( ! function_exists('imagecreatefrompng')) + { + $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); + return FALSE; + } + return imagecreatefrompng($path); + default: + $this->set_error(array('imglib_unsupported_imagecreate')); + return FALSE; } - - $this->set_error(array('imglib_unsupported_imagecreate')); - return FALSE; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index bb0ea7b50..db45a80fc 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From ea41c8aa1951216b6a9ccc99832d69d2b41c5ead Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 26 Feb 2014 18:31:02 +0200 Subject: Don't use error suppression on realpath() + style adjustments --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index db45a80fc..ac3db416d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -493,9 +493,9 @@ class CI_Image_lib { * Either way, we'll try use realpath to generate the * full server path in order to more reliably read it. */ - if (function_exists('realpath') && @realpath($this->source_image) !== FALSE) + if (($full_source_path = realpath($this->source_image)) !== FALSE) { - $full_source_path = str_replace('\\', '/', realpath($this->source_image)); + $full_source_path = str_replace('\\', '/', $full_source_path); } else { -- cgit v1.2.3-24-g4f1b From 7cf682abf46bcaa112b63c500a884ba25c0dd8b3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Mar 2014 14:55:45 +0200 Subject: Partially revert PR #2190 The core shouldn't depend on constants that are not defined by itself --- system/libraries/Image_lib.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ac3db416d..df0df3fec 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -734,7 +734,7 @@ class CI_Image_lib { { if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) { - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); } return TRUE; @@ -811,7 +811,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 666 - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); return TRUE; } @@ -881,7 +881,7 @@ class CI_Image_lib { } // Set the file to 777 - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); return TRUE; } @@ -969,7 +969,7 @@ class CI_Image_lib { // we have to rename the temp file. copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); return TRUE; } @@ -1014,7 +1014,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); return TRUE; } @@ -1087,7 +1087,7 @@ class CI_Image_lib { imagedestroy($src_img); // Set the file to 777 - @chmod($this->full_dst_path, FILE_WRITE_MODE); + @chmod($this->full_dst_path, 0666); return TRUE; } -- cgit v1.2.3-24-g4f1b From 7a0c08ec5c88a17d8096f3942493ce59766a445d Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Thu, 13 Mar 2014 20:02:44 +0200 Subject: Image_lib - minor corrections on some comments. --- system/libraries/Image_lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index df0df3fec..f1339b57a 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -880,7 +880,7 @@ class CI_Image_lib { return FALSE; } - // Set the file to 777 + // Set the file to 666 @chmod($this->full_dst_path, 0666); return TRUE; @@ -1013,7 +1013,7 @@ class CI_Image_lib { imagedestroy($dst_img); imagedestroy($src_img); - // Set the file to 777 + // Set the file to 666 @chmod($this->full_dst_path, 0666); return TRUE; @@ -1086,7 +1086,7 @@ class CI_Image_lib { // Kill the file handles imagedestroy($src_img); - // Set the file to 777 + // Set the file to 666 @chmod($this->full_dst_path, 0666); return TRUE; -- cgit v1.2.3-24-g4f1b From 459657415189f4fe3f8d4eb05b209ab78409f9b0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 27 Aug 2014 20:40:11 +0300 Subject: Fix #2963 Changed all file permissions settings throught the framework and the documentation. Also added configuration settings for CI_Log and CI_Image_lib --- system/libraries/Image_lib.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index f1339b57a..39753705b 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -326,6 +326,13 @@ class CI_Image_lib { */ public $full_dst_path = ''; + /** + * File permissions + * + * @var int + */ + public $file_permissions = 0644; + /** * Name of function to create image * @@ -734,7 +741,7 @@ class CI_Image_lib { { if ($this->source_image !== $this->new_image && @copy($this->full_src_path, $this->full_dst_path)) { - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); } return TRUE; @@ -810,8 +817,7 @@ class CI_Image_lib { imagedestroy($dst_img); imagedestroy($src_img); - // Set the file to 666 - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); return TRUE; } @@ -880,8 +886,7 @@ class CI_Image_lib { return FALSE; } - // Set the file to 666 - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); return TRUE; } @@ -969,7 +974,7 @@ class CI_Image_lib { // we have to rename the temp file. copy($this->dest_folder.'netpbm.tmp', $this->full_dst_path); unlink($this->dest_folder.'netpbm.tmp'); - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); return TRUE; } @@ -1013,8 +1018,7 @@ class CI_Image_lib { imagedestroy($dst_img); imagedestroy($src_img); - // Set the file to 666 - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); return TRUE; } @@ -1086,8 +1090,7 @@ class CI_Image_lib { // Kill the file handles imagedestroy($src_img); - // Set the file to 666 - @chmod($this->full_dst_path, 0666); + chmod($this->full_dst_path, $this->file_permissions); return TRUE; } -- cgit v1.2.3-24-g4f1b From b23b8fc9aa468021d1260c12696b2b48e6c8a90b Mon Sep 17 00:00:00 2001 From: Дмитрий Date: Mon, 20 Oct 2014 00:36:55 +0400 Subject: We can preserve transparency for PNG images --- system/libraries/Image_lib.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 39753705b..1577887c2 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1201,6 +1201,13 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } + // We can preserve transparency for PNG images + if ($this->image_type === 3) + { + imagealphablending($src_img, FALSE); + imagesavealpha($src_img, TRUE); + } + // Output the image if ($this->dynamic_output === TRUE) { @@ -1785,4 +1792,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file +/* Location: ./system/libraries/Image_lib.php */ -- cgit v1.2.3-24-g4f1b From d4818b7cc8c12e309cdc463a100b0a6d3a5bc791 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 23 Oct 2014 17:15:32 +0300 Subject: Fix #3283 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 39753705b..fb9f08fd6 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -758,7 +758,7 @@ class CI_Image_lib { if ($this->gd_version() !== FALSE) { $gd_version = str_replace('0', '', $this->gd_version()); - $v2_override = ($gd_version === 2); + $v2_override = ($gd_version == 2); } } else -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Image_lib.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index fb9f08fd6..c9fd558bc 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 1.0 + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 1.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Image_lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c9fd558bc..a70a7bb6f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From db037dbd023aeeae6d8643707945882f962b2a44 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Jan 2015 13:45:12 +0200 Subject: [ci skip] Polish changes from PR #3278 --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d653b1640..529532e60 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1212,7 +1212,7 @@ class CI_Image_lib { imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } - // We can preserve transparency for PNG images + // We can preserve transparency for PNG images if ($this->image_type === 3) { imagealphablending($src_img, FALSE); @@ -1803,4 +1803,4 @@ class CI_Image_lib { } /* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ +/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 529532e60..9ad0dd5b6 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -392,7 +392,7 @@ class CI_Image_lib { $this->initialize($props); } - log_message('debug', 'Image Lib Class Initialized'); + log_message('info', 'Image Lib Class Initialized'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Image_lib.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9ad0dd5b6..92e47507f 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1801,6 +1801,3 @@ class CI_Image_lib { } } - -/* End of file Image_lib.php */ -/* Location: ./system/libraries/Image_lib.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0779e99eeb12cb137eed77cf580add374afa71a5 Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 31 Jan 2015 11:57:07 -0700 Subject: Fixed Watermark function to work without drop shadow --- system/libraries/Image_lib.php | 76 +++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 30 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 92e47507f..aae062e47 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1311,12 +1311,14 @@ class CI_Image_lib { $y_axis = $this->wm_vrt_offset + $this->wm_padding; if ($this->wm_use_drop_shadow === FALSE) + { $this->wm_shadow_distance = 0; + } $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); - // Set verticle alignment + // Set vertical alignment if ($this->wm_vrt_alignment === 'M') { $y_axis += ($this->orig_height / 2) + ($fontheight / 2); @@ -1325,53 +1327,67 @@ class CI_Image_lib { { $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); } - - $x_shad = $x_axis + $this->wm_shadow_distance; - $y_shad = $y_axis + $this->wm_shadow_distance; - + + // Set horizontal alignment + if ($this->wm_hor_alignment === 'R') + { + $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + } + elseif ($this->wm_hor_alignment === 'C') + { + $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); + } + if ($this->wm_use_drop_shadow) { - // Set horizontal alignment - if ($this->wm_hor_alignment === 'R') - { - $x_shad += $this->orig_width - ($fontwidth * strlen($this->wm_text)); - $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); - } - elseif ($this->wm_hor_alignment === 'C') - { - $x_shad += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); - $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); - } - - /* Set RGB values for text and shadow + // Offset from text + $x_shad = $x_axis + $this->wm_shadow_distance; + $y_shad = $y_axis + $this->wm_shadow_distance; + + /* Set RGB values for shadow * * First character is #, so we don't really need it. * Get the rest of the string and split it into 2-length * hex values: */ - $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); - $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); - - // Add the text to the source image + + // Add the shadow to the source image if ($this->wm_use_truetype) { imagettftext($src_img, $this->wm_font_size, 0, $x_shad, $y_shad, $drp_color, $this->wm_font_path, $this->wm_text); - imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); } else { imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); - imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } + } + + /* Set RGB values for text + * + * First character is #, so we don't really need it. + * Get the rest of the string and split it into 2-length + * hex values: + */ + $txt_color = str_split(substr($this->wm_font_color, 1, 6), 2); + $txt_color = imagecolorclosest($src_img, hexdec($txt_color[0]), hexdec($txt_color[1]), hexdec($txt_color[2])); - // We can preserve transparency for PNG images - if ($this->image_type === 3) - { - imagealphablending($src_img, FALSE); - imagesavealpha($src_img, TRUE); - } + // Add the text to the source image + if ($this->wm_use_truetype) + { + imagettftext($src_img, $this->wm_font_size, 0, $x_axis, $y_axis, $txt_color, $this->wm_font_path, $this->wm_text); + } + else + { + imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); + } + + // We can preserve transparency for PNG images + if ($this->image_type === 3) + { + imagealphablending($src_img, FALSE); + imagesavealpha($src_img, TRUE); } // Output the final image -- cgit v1.2.3-24-g4f1b From 9c855325189e7ec1ecf2f4666280af038b6cb00e Mon Sep 17 00:00:00 2001 From: omar Date: Sat, 31 Jan 2015 11:58:03 -0700 Subject: Fixed horizontal position of watermark text when using drop shadow --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index aae062e47..e056654bb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1331,7 +1331,7 @@ class CI_Image_lib { // Set horizontal alignment if ($this->wm_hor_alignment === 'R') { - $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)); + $x_axis += $this->orig_width - ($fontwidth * strlen($this->wm_text)) - $this->wm_shadow_distance; } elseif ($this->wm_hor_alignment === 'C') { -- cgit v1.2.3-24-g4f1b From fbde2798688ab99cfe3fdd22746d60f0877b2c27 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 May 2015 11:03:06 +0300 Subject: Fix #3846 --- system/libraries/Image_lib.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index e056654bb..6374aacdd 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1055,8 +1055,11 @@ class CI_Image_lib { if ($this->rotation_angle === 'hor') { - for ($i = 0; $i < $height; $i++, $left = 0, $right = $width-1) + for ($i = 0; $i < $height; $i++) { + $left = 0; + $right = $width - 1; + while ($left < $right) { $cl = imagecolorat($src_img, $left, $i); @@ -1072,18 +1075,21 @@ class CI_Image_lib { } else { - for ($i = 0; $i < $width; $i++, $top = 0, $bot = $height-1) + for ($i = 0; $i < $width; $i++) { - while ($top < $bot) + $top = 0; + $bottom = $height - 1; + + while ($top < $botttom) { $ct = imagecolorat($src_img, $i, $top); - $cb = imagecolorat($src_img, $i, $bot); + $cb = imagecolorat($src_img, $i, $bottom); imagesetpixel($src_img, $i, $top, $cb); - imagesetpixel($src_img, $i, $bot, $ct); + imagesetpixel($src_img, $i, $bottom, $ct); $top++; - $bot--; + $bottom--; } } } -- cgit v1.2.3-24-g4f1b From 5d78fd839120419ba7c0642f120313543af99b99 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 May 2015 18:19:01 +0300 Subject: Fix an undefined variable error from fbde2798688ab99cfe3fdd22746d60f0877b2c27 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 6374aacdd..ce6c42b02 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1080,7 +1080,7 @@ class CI_Image_lib { $top = 0; $bottom = $height - 1; - while ($top < $botttom) + while ($top < $bottom) { $ct = imagecolorat($src_img, $i, $top); $cb = imagecolorat($src_img, $i, $bottom); -- cgit v1.2.3-24-g4f1b From 3a1975956dfd99dd2cab05e530c8aecb0984b4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 21 May 2015 01:05:06 +0300 Subject: [ci skip] Trim some whitespace from Image_lib --- system/libraries/Image_lib.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index ce6c42b02..c69283a7c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -845,7 +845,7 @@ class CI_Image_lib { */ public function image_process_imagemagick($action = 'resize') { - // Do we have a vaild library path? + // Do we have a vaild library path? if ($this->library_path === '') { $this->set_error('imglib_libpath_invalid'); @@ -1010,7 +1010,7 @@ class CI_Image_lib { // going to have to figure out how to determine the color // of the alpha channel in a future release. - $white = imagecolorallocate($src_img, 255, 255, 255); + $white = imagecolorallocate($src_img, 255, 255, 255); // Rotate it! $dst_img = imagerotate($src_img, $this->rotation_angle, $white); @@ -1333,7 +1333,7 @@ class CI_Image_lib { { $y_axis += $this->orig_height - $fontheight - $this->wm_shadow_distance - ($fontheight / 2); } - + // Set horizontal alignment if ($this->wm_hor_alignment === 'R') { @@ -1343,13 +1343,13 @@ class CI_Image_lib { { $x_axis += floor(($this->orig_width - ($fontwidth * strlen($this->wm_text))) / 2); } - + if ($this->wm_use_drop_shadow) { // Offset from text $x_shad = $x_axis + $this->wm_shadow_distance; $y_shad = $y_axis + $this->wm_shadow_distance; - + /* Set RGB values for shadow * * First character is #, so we don't really need it. @@ -1358,7 +1358,7 @@ class CI_Image_lib { */ $drp_color = str_split(substr($this->wm_shadow_color, 1, 6), 2); $drp_color = imagecolorclosest($src_img, hexdec($drp_color[0]), hexdec($drp_color[1]), hexdec($drp_color[2])); - + // Add the shadow to the source image if ($this->wm_use_truetype) { @@ -1369,7 +1369,7 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); } } - + /* Set RGB values for text * * First character is #, so we don't really need it. @@ -1388,7 +1388,7 @@ class CI_Image_lib { { imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } - + // We can preserve transparency for PNG images if ($this->image_type === 3) { @@ -1437,7 +1437,7 @@ class CI_Image_lib { switch ($image_type) { - case 1 : + case 1: if ( ! function_exists('imagecreatefromgif')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); @@ -1445,7 +1445,7 @@ class CI_Image_lib { } return imagecreatefromgif($path); - case 2 : + case 2: if ( ! function_exists('imagecreatefromjpeg')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); @@ -1453,7 +1453,7 @@ class CI_Image_lib { } return imagecreatefromjpeg($path); - case 3 : + case 3: if ( ! function_exists('imagecreatefrompng')) { $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); -- cgit v1.2.3-24-g4f1b From 10fb7d17b2025de4963da8b0108fda4da36ade11 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 3 Aug 2015 10:05:29 +0300 Subject: [ci skip] Normalize tabs/spaces Partial changes from PR #4016 --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index c69283a7c..e813efd89 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -779,7 +779,7 @@ class CI_Image_lib { $this->y_axis = 0; } - // Create the image handle + // Create the image handle if ( ! ($src_img = $this->image_create_gd())) { return FALSE; @@ -1195,7 +1195,7 @@ class CI_Image_lib { $x_axis += $this->orig_width - $wm_width; } - // Build the finalized image + // Build the finalized image if ($wm_img_type === 3 && function_exists('imagealphablending')) { @imagealphablending($src_img, TRUE); -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index e813efd89..cc865fd81 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index cc865fd81..d3a832415 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 1.0.0 * @filesource */ @@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Image_lib * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/libraries/image_lib.html + * @link https://codeigniter.com/user_guide/libraries/image_lib.html */ class CI_Image_lib { -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index d3a832415..f594b7125 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From eac4adfc24d1ad60af2bc3e08222ee7e5858f638 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 22 Mar 2016 11:24:14 +0200 Subject: [ci skip] Validate width, height config values --- system/libraries/Image_lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index f594b7125..edd13372d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -456,7 +456,7 @@ class CI_Image_lib { { if (property_exists($this, $key)) { - if (in_array($key, array('wm_font_color', 'wm_shadow_color'))) + if (in_array($key, array('wm_font_color', 'wm_shadow_color'), TRUE)) { if (preg_match('/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i', $val, $matches)) { @@ -478,6 +478,10 @@ class CI_Image_lib { continue; } } + elseif (in_array($key, array('width', 'height'), TRUE) && ! ctype_digit((string) $val)) + { + continue; + } $this->$key = $val; } -- cgit v1.2.3-24-g4f1b From b3f6934cb870f2da9c9891968e6f4d98effa741e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 22 Mar 2016 11:31:58 +0200 Subject: [ci skip] Escape image paths passed as shell arguments to imagemagick --- system/libraries/Image_lib.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index edd13372d..24fe8c68d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -866,27 +866,28 @@ class CI_Image_lib { if ($action === 'crop') { - $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis.' "'.$this->full_src_path.'" "'.$this->full_dst_path .'" 2>&1'; + $cmd .= ' -crop '.$this->width.'x'.$this->height.'+'.$this->x_axis.'+'.$this->y_axis; } elseif ($action === 'rotate') { - $angle = ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') - ? '-flop' : '-rotate '.$this->rotation_angle; - - $cmd .= ' '.$angle.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + $cmd .= ($this->rotation_angle === 'hor' OR $this->rotation_angle === 'vrt') + ? ' -flop' + : ' -rotate '.$this->rotation_angle; } else // Resize { if($this->maintain_ratio === TRUE) { - $cmd .= ' -resize '.$this->width.'x'.$this->height.' "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + $cmd .= ' -resize '.$this->width.'x'.$this->height; } else { - $cmd .= ' -resize '.$this->width.'x'.$this->height.'\! "'.$this->full_src_path.'" "'.$this->full_dst_path.'" 2>&1'; + $cmd .= ' -resize '.$this->width.'x'.$this->height.'\!'; } } + $cmd .= ' "'.escapeshellarg($this->full_src_path).'" "'.escapeshellarg($this->full_dst_path).'" 2>&1'; + $retval = 1; // exec() might be disabled if (function_usable('exec')) -- cgit v1.2.3-24-g4f1b From b9f53a8d7a96bad5c6f1ff7e41a075fcb5d8fb5c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 29 Jul 2016 11:31:05 +0300 Subject: [ci skip] Fix #4736 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 24fe8c68d..7ec8ba365 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -886,7 +886,7 @@ class CI_Image_lib { } } - $cmd .= ' "'.escapeshellarg($this->full_src_path).'" "'.escapeshellarg($this->full_dst_path).'" 2>&1'; + $cmd .= escapeshellarg($this->full_src_path).' '.escapeshellarg($this->full_dst_path).' 2>&1'; $retval = 1; // exec() might be disabled -- cgit v1.2.3-24-g4f1b From be8bd923329cf233fb3828afab5c3b4ceef296ec Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 7 Nov 2016 12:31:31 +0200 Subject: Fix #4902 --- system/libraries/Image_lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 7ec8ba365..06cdde0b8 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -886,7 +886,7 @@ class CI_Image_lib { } } - $cmd .= escapeshellarg($this->full_src_path).' '.escapeshellarg($this->full_dst_path).' 2>&1'; + $cmd .= ' '.escapeshellarg($this->full_src_path).' '.escapeshellarg($this->full_dst_path).' 2>&1'; $retval = 1; // exec() might be disabled -- cgit v1.2.3-24-g4f1b From 961271dc3d02d7b2f71847983c8e5a03ca003582 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Dec 2016 12:48:57 +0200 Subject: [ci skip] Fix #4937 --- system/libraries/Image_lib.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 06cdde0b8..39a30f0f5 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -544,35 +544,28 @@ class CI_Image_lib { */ if ($this->new_image === '') { - $this->dest_image = $this->source_image; + $this->dest_image = $this->source_image; $this->dest_folder = $this->source_folder; } - elseif (strpos($this->new_image, '/') === FALSE) + elseif (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE) { + $this->dest_image = $this->new_image; $this->dest_folder = $this->source_folder; - $this->dest_image = $this->new_image; } else { - if (strpos($this->new_image, '/') === FALSE && strpos($this->new_image, '\\') === FALSE) - { - $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); - } - else - { - $full_dest_path = $this->new_image; - } + $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); // Is there a file name? if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) { + $this->dest_image = $this->source_image; $this->dest_folder = $full_dest_path.'/'; - $this->dest_image = $this->source_image; } else { $x = explode('/', $full_dest_path); - $this->dest_image = end($x); + $this->dest_image = end($x); $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); } } -- cgit v1.2.3-24-g4f1b From f2a613d67c23ba253f35a73d208e0dcaf6080b40 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Dec 2016 11:39:38 +0200 Subject: Really fix #4937 --- system/libraries/Image_lib.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 39a30f0f5..475649c46 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -554,20 +554,20 @@ class CI_Image_lib { } else { - $full_dest_path = str_replace('\\', '/', realpath($this->new_image)); - // Is there a file name? - if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $full_dest_path)) + if ( ! preg_match('#\.(jpg|jpeg|gif|png)$#i', $this->new_image)) { $this->dest_image = $this->source_image; - $this->dest_folder = $full_dest_path.'/'; + $this->dest_folder = $this->new_image; } else { - $x = explode('/', $full_dest_path); + $x = explode('/', str_replace('\\', '/', $this->new_image)); $this->dest_image = end($x); - $this->dest_folder = str_replace($this->dest_image, '', $full_dest_path); + $this->dest_folder = str_replace($this->dest_image, '', $this->new_image); } + + $this->dest_folder = realpath($this->dest_folder).'/'; } /* Compile the finalized filenames/paths -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Image_lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 475649c46..3e45cb845 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 747deff00e0597a1285d416569ef929b14ab8373 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jan 2017 13:22:16 +0200 Subject: Merge pull request #4457 from KN4CK3R/develop Fix CI_Image_lib::get_image_properties() invalid image handling --- system/libraries/Image_lib.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 3e45cb845..9eb05c2fd 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1639,6 +1639,11 @@ class CI_Image_lib { } $vals = getimagesize($path); + if ($vals === FALSE) + { + $this->set_error('imglib_invalid_image'); + return FALSE; + } $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; -- cgit v1.2.3-24-g4f1b From 5f7302c7ea5c76fbc3fdcac88aead48deb7adcdb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 6 Jan 2017 13:26:08 +0200 Subject: [ci skip] Cosmetich changes to CI_Image_lib::get_image_properties() --- system/libraries/Image_lib.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9eb05c2fd..9ec44da0c 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1644,25 +1644,26 @@ class CI_Image_lib { $this->set_error('imglib_invalid_image'); return FALSE; } + $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); - $mime = (isset($types[$vals[2]])) ? 'image/'.$types[$vals[2]] : 'image/jpg'; + $mime = isset($types[$vals[2]]) ? 'image/'.$types[$vals[2]] : 'image/jpg'; if ($return === TRUE) { return array( - 'width' => $vals[0], - 'height' => $vals[1], - 'image_type' => $vals[2], - 'size_str' => $vals[3], - 'mime_type' => $mime - ); - } - - $this->orig_width = $vals[0]; - $this->orig_height = $vals[1]; - $this->image_type = $vals[2]; - $this->size_str = $vals[3]; - $this->mime_type = $mime; + 'width' => $vals[0], + 'height' => $vals[1], + 'image_type' => $vals[2], + 'size_str' => $vals[3], + 'mime_type' => $mime + ); + } + + $this->orig_width = $vals[0]; + $this->orig_height = $vals[1]; + $this->image_type = $vals[2]; + $this->size_str = $vals[3]; + $this->mime_type = $mime; return TRUE; } -- cgit v1.2.3-24-g4f1b From 8f9ab65270ae033c5637f8a7d26ae834e9a71d5e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 10 Jan 2017 12:30:38 +0200 Subject: [ci skip] CI_Image_lib to set gd.jpeg_ignore_warning = 1 See #4967 --- system/libraries/Image_lib.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'system/libraries/Image_lib.php') diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 9ec44da0c..88c9e7ede 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -392,6 +392,16 @@ class CI_Image_lib { $this->initialize($props); } + /** + * A work-around for some improperly formatted, but + * usable JPEGs; known to be produced by Samsung + * smartphones' front-facing cameras. + * + * @see https://github.com/bcit-ci/CodeIgniter/issues/4967 + * @see https://bugs.php.net/bug.php?id=72404 + */ + ini_set('gd.jpeg_ignore_warning', 1); + log_message('info', 'Image Lib Class Initialized'); } -- cgit v1.2.3-24-g4f1b