Debian Codegraph @

docs/content/en/functions/images/Filter.md

raw
1 ---
2 title: images.Filter
3 description: Returns a new image resource created by applying one or more image filters to the given image resource.
4 categories: []
5 keywords: [filter]
6 params:
7 functions_and_methods:
8 aliases: []
9 returnType: images.ImageResource
10 signatures: [images.Filter FILTER... RESOURCE]
11 ---
12
13 {{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
14
15 The `images.Filter` function 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 `images.Filter` function 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 images.Filter images.Grayscale . }}
29 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
30 {{ end }}
31 {{ end }}
32 ```
33
34 To apply two or more filters, executing from left to right:
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 images.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 [`Filter`][] method on a `Resource` object.
49
50 ## Example
51
52 ```go-html-template
53 {{ with resources.Get "images/original.jpg" }}
54 {{ with images.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 `images.Filter` function, or with the `Filter` method on a `Resource` object.
71
72 {{% render-list-of-pages-in-section path=/functions/images filter=functions_images_no_filters filterType=exclude %}}
73
74 [`Filter`]: /methods/resource/filter/
75 [`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/