Index: branches/RC/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r11936 -r11937 --- branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11936) +++ branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 11937) @@ -1,6 +1,6 @@ _cropImage($dst_image_rs, $params); - // 3. apply watermark + // 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); } else { - // 3. apply watermark + 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['target_width'], $params['target_height'], $params); } @@ -186,6 +196,38 @@ } /** + * Fills margins (if any) of resized are with given color + * + * @param resource $src_image_rs resized image resource + * @param Array $params crop parameters + * @return resource + */ + function &_applyFill(&$src_image_rs, $params) + { + $x_position = round(($params['max_width'] - $params['target_width']) / 2); // center + $y_position = round(($params['max_height'] - $params['target_height']) / 2); // center + + // crop resized image + $fill_image_rs = imagecreatetruecolor($params['max_width'], $params['max_height']); + + $fill = $params['fill']; + + if (substr($fill, 0, 1) == '#') { + // hexdecimal color + $color = imagecolorallocate($fill_image_rs, hexdec( substr($fill, 1, 2) ), hexdec( substr($fill, 3, 2) ), hexdec( substr($fill, 5, 2) )); + } + else { + // for now we don't support color names, but we will in future + return $src_image_rs; + } + + imagefill($fill_image_rs, 0, 0, $color); + imagecopy($fill_image_rs, $src_image_rs, $x_position, $y_position, 0, 0, $params['target_width'], $params['target_height']); + + return $fill_image_rs; + } + + /** * Crop given image resource using given params and return resulting image resource * * @param resource $src_image_rs resized image resource