/** * Add filter to current image * * @param string|callable $filter * @return $this * * @throws Exception */ public function addFilter($filter) { $args = func_get_args(); $args[0] = $this->_image; $newImage = null; if (is_string($filter)) { $filterClass = __NAMESPACE__ . '\\Filter'; if (method_exists($filterClass, $filter)) { $newImage = call_user_func_array(array($filterClass, $filter), $args); } else { throw new Exception('Undefined Image Filter: ' . $filter); } } elseif (is_callable($filter)) { $newImage = call_user_func_array($filter, $args); } if (Helper::isGdRes($newImage)) { $this->_replaceImage($newImage); } return $this; }