Index: branches/RC/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r11938 -r11939 --- branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11938) +++ branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11939) @@ -1,6 +1,6 @@ 0 || $params['max_height'] > 0) { list ($params['target_width'], $params['target_height'], $needs_resize) = $this->GetImageDimensions($src_image, $params['max_width'], $params['max_height'], $params); + if (!is_numeric($params['max_width'])) { + $params['max_width'] = $params['target_width']; + } + + if (!is_numeric($params['max_height'])) { + $params['max_height'] = $params['target_height']; + } + $src_path = dirname($src_image); if ($needs_resize || array_key_exists('wm_filename', $params) && $params['wm_filename']) { @@ -163,28 +171,20 @@ // 1. resize imagecopyresampled($dst_image_rs, $src_image_rs, 0, 0, 0, 0, $params['target_width'], $params['target_height'], $image_info[0], $image_info[1]); - // 2. crop + $watermark_size = 'target'; + 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); - - // 3. don't apply fill, when crop is used, because crop doesn't create margins to fill - - // 4. apply watermark - $dst_image_rs =& $this->_applyWatermark($dst_image_rs, $params['max_width'], $params['max_height'], $params); + $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); + $watermark_size = 'max'; } - else { - if (array_key_exists('fill', $params)) { - // 3. apply fill - $dst_image_rs =& $this->_applyFill($dst_image_rs, $params); - // 4. apply watermark - $dst_image_rs =& $this->_applyWatermark($dst_image_rs, $params['max_width'], $params['max_height'], $params); - } - else { - // 4. apply watermark - $dst_image_rs =& $this->_applyWatermark($dst_image_rs, $params['target_width'], $params['target_height'], $params); - } - } + // 3. apply watermark + $dst_image_rs =& $this->_applyWatermark($dst_image_rs, $params[$watermark_size . '_width'], $params[$watermark_size . '_height'], $params); return @$write_function($dst_image_rs, $params['dst_image'], 100); } @@ -241,7 +241,7 @@ function &_cropImage(&$src_image_rs, $params) { if ($params['crop_x'] == 'c') { - $x_position = round($params['target_width'] / 2 - $params['max_width'] / 2); // center + $x_position = round(($params['max_width'] - $params['target_width']) / 2); // center } elseif ($params['crop_x'] >= 0) { $x_position = $params['crop_x']; // margin from left @@ -251,7 +251,7 @@ } if ($params['crop_y'] == 'c') { - $y_position = round($params['target_height'] / 2 - $params['max_height'] / 2); // center + $y_position = round(($params['max_height'] - $params['target_height']) / 2); // center } elseif ($params['crop_y'] >= 0) { $y_position = $params['crop_y']; // margin from top @@ -262,8 +262,10 @@ // crop resized image $crop_image_rs = imagecreatetruecolor($params['max_width'], $params['max_height']); - imagecopyresampled($crop_image_rs, $src_image_rs, 0, 0, $x_position, $y_position, $params['target_width'], $params['target_height'], $params['target_width'], $params['target_height']); + $crop_image_rs =& $this->_applyFill($crop_image_rs, $params); + imagecopy($crop_image_rs, $src_image_rs, $x_position, $y_position, 0, 0, $params['target_width'], $params['target_height']); + return $crop_image_rs; }