blob: 550b06401e41119da008b10adf2dcdc01cd837c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
---
title: Process
description: Applicable to images, returns an image resource processed with the given specification.
categories: []
keywords: []
action:
related:
- methods/resource/Crop
- methods/resource/Fit
- methods/resource/Fill
- methods/resource/Resize
- functions/images/Process
returnType: images.ImageResource
signatures: [RESOURCE.Process SPEC]
toc: true
---
Process an image with the given specification. The specification can contain an optional action, one of `crop`, `fill`, `fit`, or `resize`. This means that you can use this method instead of [`Crop`], [`Fill`], [`Fit`], or [`Resize`].
```go-html-template
{{ with resources.Get "images/original.jpg" }}
{{ with .Process "crop 200x200" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
```
You can also use this method to apply simple transformations such as rotation and conversion:
```go-html-template
{{/* Rotate 90 degrees counter-clockwise. */}}
{{ $image := $image.Process "r90" }}
{{/* Convert to WebP. */}}
{{ $image := $image.Process "webp" }}
```
The `Process` method is also available as a filter, which is more effective if you need to apply multiple filters to an image. See [`images.Process`].
{{% include "methods/resource/_common/global-page-remote-resources.md" %}}
{{% include "/methods/resource/_common/processing-spec.md" %}}
## Example
```go-html-template
{{ with resources.Get "images/original.jpg" }}
{{ with .Process "crop 200x200 topright webp q85 lanczos" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
```
{{< img
src="images/examples/zion-national-park.jpg"
alt="Zion National Park"
filter="Process"
filterArgs="crop 200x200 topright webp q85 lanczos"
example=true
>}}
[`Crop`]: /methods/resource/crop/
[`Fill`]: /methods/resource/fill/
[`Fit`]: /methods/resource/fit/
[`Resize`]: /methods/resource/resize/
[`images.Process`]: /functions/images/process/
|