Index: image_helper.php =================================================================== --- image_helper.php (revision 13134) +++ image_helper.php (working copy) @@ -171,7 +171,9 @@ if ($src_image_rs) { $dst_image_rs = imagecreatetruecolor($params['target_width'], $params['target_height']); // resize target size - if (($file_extension == 'gif') || ($file_extension == 'png')) { + $preserve_transparency = ($file_extension == 'gif') || ($file_extension == 'png'); + + if ($preserve_transparency) { // preserve transparency of PNG and GIF images $dst_image_rs = $this->_preserveTransparency($src_image_rs, $dst_image_rs, $image_info[2]); } @@ -183,11 +185,11 @@ if (array_key_exists('crop_x', $params) || array_key_exists('crop_y', $params)) { // 2.1. crop image to given size - $dst_image_rs =& $this->_cropImage($dst_image_rs, $params); + $dst_image_rs =& $this->_cropImage($dst_image_rs, $params, $preserve_transparency ? $image_info[2] : false); $watermark_size = 'max'; } elseif (array_key_exists('fill', $params)) { // 2.2. fill image margins from resize with given color - $dst_image_rs =& $this->_applyFill($dst_image_rs, $params); + $dst_image_rs =& $this->_applyFill($dst_image_rs, $params, $preserve_transparency ? $image_info[2] : false); $watermark_size = 'max'; } @@ -259,9 +261,10 @@ * * @param resource $src_image_rs resized image resource * @param Array $params crop parameters + * @param int $image_type * @return resource */ - function &_applyFill(&$src_image_rs, $params) + function &_applyFill(&$src_image_rs, $params, $image_type = false) { $x_position = round(($params['max_width'] - $params['target_width']) / 2); // center $y_position = round(($params['max_height'] - $params['target_height']) / 2); // center @@ -269,6 +272,10 @@ // crop resized image $fill_image_rs = imagecreatetruecolor($params['max_width'], $params['max_height']); + if ($image_type !== false) { + $fill_image_rs = $this->_preserveTransparency($src_image_rs, $fill_image_rs, $image_type); + } + $fill = $params['fill']; if (substr($fill, 0, 1) == '#') { @@ -291,9 +298,10 @@ * * @param resource $src_image_rs resized image resource * @param Array $params crop parameters + * @param int $image_type * @return resource */ - function &_cropImage(&$src_image_rs, $params) + function &_cropImage(&$src_image_rs, $params, $image_type = false) { if ($params['crop_x'] == 'c') { $x_position = round(($params['max_width'] - $params['target_width']) / 2); // center @@ -317,8 +325,16 @@ // crop resized image $crop_image_rs = imagecreatetruecolor($params['max_width'], $params['max_height']); - $crop_image_rs =& $this->_applyFill($crop_image_rs, $params); + if ($image_type !== false) { + $crop_image_rs = $this->_preserveTransparency($src_image_rs, $crop_image_rs, $image_type); + } + + if (array_key_exists('fill', $params)) { + // fill image margins from resize with given color + $crop_image_rs =& $this->_applyFill($crop_image_rs, $params, $image_type); + } + imagecopy($crop_image_rs, $src_image_rs, $x_position, $y_position, 0, 0, $params['target_width'], $params['target_height']); return $crop_image_rs;