Index: core/units/helpers/image_helper.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/units/helpers/image_helper.php (revision 15698) +++ core/units/helpers/image_helper.php (revision ) @@ -64,7 +64,12 @@ } elseif (preg_match('/default:(.*)/', $format_part, $regs)) { $res['default'] = FULL_PATH.THEMES_PATH.'/'.$regs[1]; } + elseif ( preg_match('/^filter:(.*)$/', $format_part, $regs) ) { + $format_part_params = explode('|', $regs[1]); + $res['filter_type'] = array_shift($format_part_params); + $res['filter_params'] = $format_part_params; - } + } + } return $res; } @@ -111,7 +116,7 @@ } $src_path = dirname($src_image); - $transform_keys = Array ('crop_x', 'crop_y', 'fill', 'wm_filename'); + $transform_keys = Array ('crop_x', 'crop_y', 'fill', 'wm_filename', 'filter_type'); if ($needs_resize || array_intersect(array_keys($params), $transform_keys)) { // resize required OR watermarking required -> change resulting image name ! @@ -218,6 +223,9 @@ return @$write_function($dst_image_rs, $params['dst_image']); } + // 4. apply filter + $this->applyFilter($dst_image_rs, $params); + return @$write_function($dst_image_rs, $params['dst_image'], $write_function == 'imagepng' ? 0 : 100); } } @@ -408,6 +416,36 @@ imagecopy($src_image_rs, $watermark_img_rs, $x_position, $y_position, 0, 0, $watermark_width, $watermark_height); return $src_image_rs; + } + + /** + * Applies filter to an image. + * + * @param resource $src_image_rs Source image. + * @param array $params Parameters. + * + * @return boolean + * @access protected + * @throws InvalidArgumentException When unknown filter type given. + * @link http://php.net/manual/en/function.imagefilter.php + */ + protected function applyFilter(&$src_image_rs, array $params) + { + if ( !array_key_exists('filter_type', $params) ) { + return true; + } + + $filter_type = strtoupper($params['filter_type']); + $filter_params = (array)$params['filter_params']; + + if ( !defined('IMG_FILTER_' . $filter_type) ) { + throw new InvalidArgumentException(sprintf('Unknown filter type "%s"', $filter_type)); + } + + array_unshift($filter_params, constant('IMG_FILTER_' . $filter_type)); + array_unshift($filter_params, $src_image_rs); + + return call_user_func_array('imagefilter', $filter_params); } /** \ No newline at end of file