| 1 |
--- |
| 2 |
title: Resize |
| 3 |
description: Returns a new image resource resized according to the given processing specification. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: images.ImageResource |
| 9 |
signatures: [RESOURCE.Resize SPECIFICATION] |
| 10 |
--- |
| 11 |
|
| 12 |
{{% include "/_common/methods/resource/global-page-remote-resources.md" %}} |
| 13 |
|
| 14 |
The `Resize` 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 |
Resize an image according to the given processing specification. You may specify only the width (such as `300x`) or only the height (such as `x150`) for proportional scaling. |
| 22 |
|
| 23 |
If you specify both width and height (such as `300x150`), the resulting image will be scaled to those exact dimensions. If the target aspect ratio differs from the original, the image will be non-proportionally scaled (stretched or squashed). |
| 24 |
|
| 25 |
```go-html-template |
| 26 |
{{ with resources.Get "images/original.jpg" }} |
| 27 |
{{ with .Resize "300x" }} |
| 28 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 29 |
{{ end }} |
| 30 |
{{ end }} |
| 31 |
``` |
| 32 |
|
| 33 |
In the example above, `"300x"` is the processing specification. |
| 34 |
|
| 35 |
{{% include "/_common/methods/resource/processing-spec.md" %}} |
| 36 |
|
| 37 |
## Example |
| 38 |
|
| 39 |
```go-html-template |
| 40 |
{{ with resources.Get "images/original.jpg" }} |
| 41 |
{{ with .Resize "300x" }} |
| 42 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 43 |
{{ end }} |
| 44 |
{{ end }} |
| 45 |
``` |
| 46 |
|
| 47 |
{{< img |
| 48 |
src="images/examples/zion-national-park.jpg" |
| 49 |
alt="Zion National Park" |
| 50 |
filter="Process" |
| 51 |
filterArgs="resize 300x" |
| 52 |
example=true |
| 53 |
>}} |
| 54 |
|
| 55 |
[`reflect.IsImageResourceProcessable`]: /functions/reflect/isimageresourceprocessable/ |