summaryrefslogtreecommitdiffstats
path: root/system/libraries/Image_lib.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:51:06 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:58:52 +0100
commitce2b69675075444c9e40b72bcdd42ab7edbbe633 (patch)
tree2932f13b0db14fe53dc0622d888318db638a017f /system/libraries/Image_lib.php
parentb6b8a6587c399bfd89e13e92ce04ee8486688e6e (diff)
update to CI 2.0
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
Diffstat (limited to 'system/libraries/Image_lib.php')
-rwxr-xr-x[-rw-r--r--]system/libraries/Image_lib.php79
1 files changed, 36 insertions, 43 deletions
diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php
index 0b29c1fbd..41f9ad393 100644..100755
--- 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 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -26,7 +26,7 @@
*/
class CI_Image_lib {
- var $image_library = 'gd2'; // Can be: imagemagick, netpbm, gd, gd2
+ 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 = '';
@@ -36,7 +36,7 @@ class CI_Image_lib {
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 $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 = '';
@@ -54,11 +54,11 @@ class CI_Image_lib {
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_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
+ var $wm_opacity = 50; // Image opacity: 1 - 100 Only works with image
// Private Vars
var $source_folder = '';
@@ -79,11 +79,10 @@ class CI_Image_lib {
/**
* Constructor
*
- * @access public
* @param string
* @return void
*/
- function CI_Image_lib($props = array())
+ public function __construct($props = array())
{
if (count($props) > 0)
{
@@ -147,7 +146,7 @@ class CI_Image_lib {
if ($this->source_image == '')
{
$this->set_error('imglib_source_image_required');
- return FALSE;
+ return FALSE;
}
/*
@@ -190,7 +189,7 @@ class CI_Image_lib {
// Set the Image Properties
if ( ! $this->get_image_properties($this->source_folder.$this->source_image))
{
- return FALSE;
+ return FALSE;
}
/*
@@ -400,7 +399,7 @@ class CI_Image_lib {
if ($this->rotation_angle == '' OR ! in_array($this->rotation_angle, $degs))
{
$this->set_error('imglib_rotation_angle_required');
- return FALSE;
+ return FALSE;
}
// Reassign the width and height
@@ -455,11 +454,11 @@ class CI_Image_lib {
{
if ($this->orig_width == $this->width AND $this->orig_height == $this->height)
{
- if ($this->source_image != $this->new_image)
- {
+ if ($this->source_image != $this->new_image)
+ {
if (@copy($this->full_src_path, $this->full_dst_path))
{
- @chmod($this->full_dst_path, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
}
}
@@ -494,14 +493,14 @@ class CI_Image_lib {
return FALSE;
}
- // Create The Image
+ // 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)
- if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
+ if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor'))
{
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
@@ -513,6 +512,13 @@ class CI_Image_lib {
}
$dst_img = $create($this->width, $this->height);
+
+ if ($this->image_type == 3) // png we can actually preserve transparency
+ {
+ imagealphablending($dst_img, FALSE);
+ imagesavealpha($dst_img, TRUE);
+ }
+
$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
@@ -534,7 +540,7 @@ class CI_Image_lib {
imagedestroy($src_img);
// Set the file to 777
- @chmod($this->full_dst_path, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
}
@@ -577,9 +583,9 @@ class CI_Image_lib {
{
switch ($this->rotation_angle)
{
- case 'hor' : $angle = '-flop';
+ case 'hor' : $angle = '-flop';
break;
- case 'vrt' : $angle = '-flip';
+ case 'vrt' : $angle = '-flip';
break;
default : $angle = '-rotate '.$this->rotation_angle;
break;
@@ -604,7 +610,7 @@ class CI_Image_lib {
}
// Set the file to 777
- @chmod($this->full_dst_path, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
}
@@ -657,7 +663,7 @@ class CI_Image_lib {
break;
case 180 : $angle = 'r180';
break;
- case 270 : $angle = 'r90';
+ case 270 : $angle = 'r90';
break;
case 'vrt' : $angle = 'tb';
break;
@@ -690,7 +696,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, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
}
@@ -705,14 +711,6 @@ class CI_Image_lib {
*/
function image_rotate_gd()
{
- // Is Image Rotation Supported?
- // this function is only supported as of PHP 4.3
- if ( ! function_exists('imagerotate'))
- {
- $this->set_error('imglib_rotate_unsupported');
- return FALSE;
- }
-
// Create the image handle
if ( ! ($src_img = $this->image_create_gd()))
{
@@ -749,7 +747,7 @@ class CI_Image_lib {
// Set the file to 777
- @chmod($this->full_dst_path, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
return true;
}
@@ -833,7 +831,7 @@ class CI_Image_lib {
imagedestroy($src_img);
// Set the file to 777
- @chmod($this->full_dst_path, DIR_WRITE_MODE);
+ @chmod($this->full_dst_path, FILE_WRITE_MODE);
return TRUE;
}
@@ -882,7 +880,7 @@ 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'];
@@ -937,7 +935,7 @@ class CI_Image_lib {
if ($wm_img_type == 3 AND function_exists('imagealphablending'))
{
@imagealphablending($src_img, TRUE);
- }
+ }
// Set RGB values for text and shadow
$rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp);
@@ -1208,11 +1206,6 @@ class CI_Image_lib {
return FALSE;
}
- if (phpversion() == '4.4.1')
- {
- @touch($this->full_dst_path); // PHP 4.4.1 bug #35060 - workaround
- }
-
if ( ! @imagejpeg($resource, $this->full_dst_path, $this->quality))
{
$this->set_error('imglib_save_failed');
@@ -1259,7 +1252,7 @@ class CI_Image_lib {
switch ($this->image_type)
{
- case 1 : imagegif($resource);
+ case 1 : imagegif($resource);
break;
case 2 : imagejpeg($resource, '', $this->quality);
break;
@@ -1377,8 +1370,8 @@ class CI_Image_lib {
* new variable needs to be known
*
* $props = array(
- * 'width' => $width,
- * 'height' => $height,
+ * 'width' => $width,
+ * 'height' => $height,
* 'new_width' => 40,
* 'new_height' => ''
* );
@@ -1439,7 +1432,7 @@ class CI_Image_lib {
{
$ext = strrchr($source_image, '.');
$name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext));
-
+
return array('ext' => $ext, 'name' => $name);
}