Debian Codegraph @

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

raw
1 ---
2 title: Crop
3 description: Returns a new image resource cropped according to the given processing specification.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: images.ImageResource
9 signatures: [RESOURCE.Crop SPECIFICATION]
10 ---
11
12 {{% include "/_common/methods/resource/global-page-remote-resources.md" %}}
13
14 The `Crop` method returns a new resource from a [processable image](g) according to the given [processing specification](#processing-specification).
15
16 > [!NOTE]
17 > Use the [`reflect.IsImageResourceProcessable`][] function to verify that an image can be processed.
18
19 ## Usage
20
21 When cropping, you must provide both width and height (such as `200x200`) within the specification. This method does not perform any resizing; it simply extracts a region of the image based on the dimensions and the [anchor](#anchor) provided, if any.
22
23 ```go-html-template
24 {{ with resources.Get "images/original.jpg" }}
25 {{ with .Crop "200x200 TopRight" }}
26 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
27 {{ end }}
28 {{ end }}
29 ```
30
31 In the example above, `"200x200 TopRight"` is the processing specification.
32
33 {{% include "/_common/methods/resource/processing-spec.md" %}}
34
35 ## Example
36
37 ```go-html-template
38 {{ with resources.Get "images/original.jpg" }}
39 {{ with .Crop "200x200 TopRight" }}
40 <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
41 {{ end }}
42 {{ end }}
43 ```
44
45 {{< img
46 src="images/examples/zion-national-park.jpg"
47 alt="Zion National Park"
48 filter="Process"
49 filterArgs="crop 200x200 TopRight"
50 example=true
51 >}}
52
53 [`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/