---
application: "Intervention Image"
version: "Version 2"
status: "eol"
---

# Image::filter

## Apply a predefined filter to the current image



> public Intervention\Image\Image filter(Intervention\Image\Filters\FilterInterface $filter)

The method applies custom filter on current image. Filters are bundles of commands which apply combined operations and effects on an image. Any filters must implement the ```Intervention\Image\Filters\FilterInterface```  and call any method that can be applied to an Intervention Image instance.

### Parameters

#### filter
Instance of your custom filter. See example of `DemoFilter` below which combines a greyscale/pixelate effect.

### Return Values
Instance of `Intervention\Image\Image`

### Examples

```php
// init new image instance
$img = Image::make('foo.jpg');

// apply filter
$img->filter(new DemoFilter(45));
```

#### DemoFilter Example

```php
namespace Intervention\Image\Filters;

class DemoFilter implements FilterInterface
{
    /**
     * Default size of filter effects
     */
    const DEFAULT_SIZE = 10;

    /**
     * Size of filter effects
     *
     * @var integer
     */
    private $size;

    /**
     * Creates new instance of filter
     *
     * @param integer $size
     */
    public function __construct($size = null)
    {
        $this->size = is_numeric($size) ? intval($size) : self::DEFAULT_SIZE;
    }

    /**
     * Applies filter effects to given image
     *
     * @param  Intervention\Image\Image $image
     * @return Intervention\Image\Image
     */
    public function applyFilter(\Intervention\Image\Image $image)
    {
        $image->pixelate($this->size);
        $image->greyscale();

        return $image;
    }
}
```

---

## Become a Sponsor

### Intervention Image needs your help to keep the project going

Intervention Image is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)