File: Process.md

package info (click to toggle)
hugo 0.158.0-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 38,848 kB
  • sloc: javascript: 31,888; ansic: 2,350; xml: 350; makefile: 195; sh: 110
file content (60 lines) | stat: -rw-r--r-- 1,987 bytes parent folder | download | duplicates (2)
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
---
title: Process
description: Applicable to images, returns a new image resource processed according to the given processing specification.
categories: []
keywords: [process]
params:
  alt_title: RESOURCE.Process
  functions_and_methods:
    returnType: images.ImageResource
    signatures: [RESOURCE.Process SPECIFICATION]
---

{{% include "/_common/methods/resource/global-page-remote-resources.md" %}}

Process an image according to the given [processing specification][]. This versatile method supports the full range of image transformations, including resizing, cropping, rotation, and format conversion, all within a single specification string.

```go-html-template
{{ with resources.Get "images/original.jpg" }}
  {{ with .Process "crop 200x200 TopRight webp q50" }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}
```

In the example above, `"crop 200x200 TopRight webp q50"` is the _processing specification_.

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 "/_common/methods/resource/processing-spec.md" %}}

## Example

```go-html-template
{{ with resources.Get "images/original.jpg" }}
  {{ with .Process "crop 200x200 TopRight webp q50" }}
    <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 q50"
  example=true
>}}

[`images.Process`]: /functions/images/process/
[processing specification]: #processing-specification