Debian Codegraph @

docs/content/en/methods/resource/Process.md

raw
1 ---
2 title: Process
3 description: Returns a new image resource processed according to the given processing specification.
4 categories: []
5 keywords: [process]
6 params:
7 alt_title: RESOURCE.Process
8 functions_and_methods:
9 returnType: images.ImageResource
10 signatures: [RESOURCE.Process SPECIFICATION]
11 ---
12
13 {{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
14
15 The `Process` method returns a new resource from a [processable image](g) according to the given [processing specification](#processing-specification).
16
17 > [!NOTE]
18 > Use the [`reflect.IsImageResourceProcessable`][] function to verify that an image can be processed.
19
20 ## Usage
21
22 This versatile method supports the full range of image transformations including resizing, cropping, rotation, and format conversion within a single specification string. Unlike specialized methods such as [`Resize`][] or [`Crop`][], you must explicitly include the [action](#action) in the specification if you are changing the image dimensions.
23
24 ```go-html-template
25 {{ with resources.Get "images/original.jpg" }}
26 {{ with .Process "crop 200x200 TopRight webp q50" }}
27 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
28 {{ end }}
29 {{ end }}
30 ```
31
32 In the example above, `"crop 200x200 TopRight webp q50"` is the processing specification.
33
34 You can also use this method to apply simple transformations such as rotation and conversion:
35
36 ```go-html-template
37 {{/* Rotate 90 degrees counter-clockwise. */}}
38 {{ $image := $image.Process "r90" }}
39
40 {{/* Convert to WebP. */}}
41 {{ $image := $image.Process "webp" }}
42 ```
43
44 The `Process` method is also available as a filter. This is more effective if you need to apply multiple filters to an image. See [`images.Process`][].
45
46 {{% include "/_common/methods/resource/processing-spec.md" %}}
47
48 ## Example
49
50 ```go-html-template
51 {{ with resources.Get "images/original.jpg" }}
52 {{ with .Process "crop 200x200 TopRight webp q50" }}
53 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
54 {{ end }}
55 {{ end }}
56 ```
57
58 {{< img
59 src="images/examples/zion-national-park.jpg"
60 alt="Zion National Park"
61 filter="Process"
62 filterArgs="crop 200x200 TopRight webp q50"
63 example=true
64 >}}
65
66 [`Crop`]: /methods/resource/crop/
67 [`Resize`]: /methods/resource/resize/
68 [`images.Process`]: /functions/images/process/
69 [`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/