| 1 |
--- |
| 2 |
title: Fill |
| 3 |
description: Applicable to images, returns a new image resource cropped and resized according to the given processing specification. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: images.ImageResource |
| 9 |
signatures: [RESOURCE.Fill SPECIFICATION] |
| 10 |
--- |
| 11 |
|
| 12 |
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}} |
| 13 |
|
| 14 |
The `Fill` 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 filling, you must provide both width and height (such as `500x200`) within the specification. `Fill` maintains the original aspect ratio by resizing the image to cover the target area and cropping any overflowing pixels based on the [anchor](#anchor) provided. |
| 22 |
|
| 23 |
```go-html-template |
| 24 |
{{ with resources.Get "images/original.jpg" }} |
| 25 |
{{ with .Fill "500x200 TopRight" }} |
| 26 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 27 |
{{ end }} |
| 28 |
{{ end }} |
| 29 |
``` |
| 30 |
|
| 31 |
In the example above, `"500x200 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 .Fill "500x200 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="fill 500x200 TopRight" |
| 50 |
example=true |
| 51 |
>}} |
| 52 |
|
| 53 |
[`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/ |