[eluser]rip_pit[/eluser]
Great!
here's how someone can use this without modifying the core function (easiest for updating)
Do not edit /system/librairies/Image_lib.php
Instead, create a new file in your /application/libraries/ folder
And call it MY_Image_lib.php
Copy and paste this code :
/application/libraries/MY_Image_lib.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter Image Manipulation Class fixed
* fixed method "image_process_gd" to keep png transparency when resizing
* more info : http://ellislab.com/forums/newreply/77836/
*/
class MY_Image_lib extends CI_Image_lib {
function MY_Image_lib() {
parent::CI_Image_lib();
}
/**
* FIXED function to keep transparency
* Image Process Using GD/GD2
*
* This function will resize or crop
*
* @access public
* @param string
* @return bool
*/
function image_process_gd($action = 'resize') {
$v2_override = FALSE;
// 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->orig_width == $this->width AND $this->orig_height == $this->height) {
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);
}
}
return TRUE;
}
}
// Let's set up our values based on the action
if ($action == 'crop') {
// Reassign the source width/height if cropping
$this->orig_width = $this->width;
$this->orig_height = $this->height;
// GD 2.0 has a cropping bug so we'll test for it
if ($this->gd_version() !== FALSE) {
$gd_version = str_replace('0', '', $this->gd_version());
$v2_override = ($gd_version == 2) ? TRUE : FALSE;
}
} else {
// If resizing the x/y axis must be zero
$this->x_axis = 0;
$this->y_axis = 0;
}
// Create the image handle
if (!($src_img = $this->image_create_gd())) {
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)
if ($this->image_library == 'gd2' AND function_exists('imagecreatetruecolor')) {
$create = 'imagecreatetruecolor';
$copy = 'imagecopyresampled';
} else {
$create = 'imagecreate';
$copy = 'imagecopyresized';
}
// CODE:
// $dst_img = $create($this->width, $this->height);
// $copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
// REPLACED WITH: start
// TRANSPARENT PNG
$dst_img = imagecreatetruecolor($this->width, $this->height);
$transparent = imagecolorallocatealpha($dst_img, 0, 255, 0, 127);
imagefill($dst_img, 0, 0, $transparent);
$copy($dst_img, $src_img, 0, 0, $this->x_axis, $this->y_axis, $this->width, $this->height, $this->orig_width, $this->orig_height);
imageAlphaBlending($dst_img, false);
imageSaveAlpha($dst_img, true);
// REPLACED WITH: end
// Show the image
if ($this->dynamic_output == TRUE) {
$this->image_display_gd($dst_img);
} else {
// Or save it
if (!$this->image_save_gd($dst_img)) {
return FALSE;
}
}
// Kill the file handles
imagedestroy($dst_img);
imagedestroy($src_img);
// Set the file to 777
@chmod($this->full_dst_path, DIR_WRITE_MODE);
return TRUE;
}
}
/* End of file MY_Image_lib.php */
/* Location: ./application/libraries/MY_Image_lib.php */
Now when you'll call Image_lib as usual, this file be auto loaded and override the core functions, using the ones defined in this new file.
read more about extending CI :http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
I hope i helped a bit because this fix helped me a lot !