| 1 |
--- |
| 2 |
title: Filter |
| 3 |
description: Applicable to images, applies one or more image filters to the given image resource. |
| 4 |
categories: [] |
| 5 |
keywords: [filter] |
| 6 |
params: |
| 7 |
alt_title: RESOURCE.Filter |
| 8 |
functions_and_methods: |
| 9 |
returnType: images.ImageResource |
| 10 |
signatures: [RESOURCE.Filter FILTER...] |
| 11 |
--- |
| 12 |
|
| 13 |
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}} |
| 14 |
|
| 15 |
The `Filter` method returns a new resource from a [processable image](g) after applying one or more [image filters](#image-filters). |
| 16 |
|
| 17 |
> [!NOTE] |
| 18 |
> Use the [`reflect.IsImageResourceProcessable`][] function to verify that an image can be processed. |
| 19 |
|
| 20 |
## Usage |
| 21 |
|
| 22 |
Use the `Filter` method to apply effects such as blurring, sharpening, or grayscale conversion. You can pass a single filter or a slice of filters. When providing a slice, Hugo applies the filters from left to right. |
| 23 |
|
| 24 |
To apply a single filter: |
| 25 |
|
| 26 |
```go-html-template |
| 27 |
{{ with resources.Get "images/original.jpg" }} |
| 28 |
{{ with .Filter images.Grayscale }} |
| 29 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 30 |
{{ end }} |
| 31 |
{{ end }} |
| 32 |
``` |
| 33 |
|
| 34 |
To apply multiple filters: |
| 35 |
|
| 36 |
```go-html-template |
| 37 |
{{ $filters := slice |
| 38 |
images.Grayscale |
| 39 |
(images.GaussianBlur 8) |
| 40 |
}} |
| 41 |
{{ with resources.Get "images/original.jpg" }} |
| 42 |
{{ with .Filter $filters }} |
| 43 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 44 |
{{ end }} |
| 45 |
{{ end }} |
| 46 |
``` |
| 47 |
|
| 48 |
You can also apply image filters using the [`images.Filter`][] function. |
| 49 |
|
| 50 |
## Example |
| 51 |
|
| 52 |
```go-html-template |
| 53 |
{{ with resources.Get "images/original.jpg" }} |
| 54 |
{{ with .Filter images.Grayscale }} |
| 55 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 56 |
{{ end }} |
| 57 |
{{ end }} |
| 58 |
``` |
| 59 |
|
| 60 |
{{< img |
| 61 |
src="images/examples/zion-national-park.jpg" |
| 62 |
alt="Zion National Park" |
| 63 |
filter="Grayscale" |
| 64 |
filterArgs="" |
| 65 |
example=true |
| 66 |
>}} |
| 67 |
|
| 68 |
## Image filters |
| 69 |
|
| 70 |
Use any of these filters with the `Filter` method. |
| 71 |
|
| 72 |
{{% render-list-of-pages-in-section path=/functions/images filter=functions_images_no_filters filterType=exclude %}} |
| 73 |
|
| 74 |
[`images.Filter`]: /functions/images/filter/ |
| 75 |
[`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/ |