mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Add $image.Process
Which supports all the existing actions: resize, crop, fit, fill. But it also allows plain format conversions: ``` {{ $img = $img.Process "webp" }} ``` Which will be a simple re-encoding of the source image. Fixes #11483
This commit is contained in:
@@ -101,12 +101,41 @@ Example 4: Skips rendering if there's problem accessing a remote resource.
|
||||
|
||||
## Image processing methods
|
||||
|
||||
The `image` resource implements the [`Resize`], [`Fit`], [`Fill`], [`Crop`], [`Filter`], [`Colors`] and [`Exif`] methods.
|
||||
The `image` resource implements the [`Process`], [`Resize`], [`Fit`], [`Fill`], [`Crop`], [`Filter`], [`Colors`] and [`Exif`] methods.
|
||||
|
||||
{{% note %}}
|
||||
Metadata (EXIF, IPTC, XMP, etc.) is not preserved during image transformation. Use the [`Exif`] method with the _original_ image to extract EXIF metadata from JPEG or TIFF images.
|
||||
{{% /note %}}
|
||||
|
||||
### Process
|
||||
|
||||
{{< new-in "0.119.0" >}}
|
||||
|
||||
Process processes the image with the given specification. The specification can contain an optional action, one of `resize`, `crop`, `fit` or `fill`. This means that you can use this method instead of [`Resize`], [`Fit`], [`Fill`], or [`Crop`].
|
||||
|
||||
See [Options](#image-processing-options) for available options.
|
||||
|
||||
You can also use this method apply image processing that does not need any scaling, e.g. format conversions:
|
||||
|
||||
```go-html-template
|
||||
{{/* Convert the image from JPG to PNG. */}}
|
||||
{{ $png := $jpg.Process "png" }}
|
||||
```
|
||||
|
||||
Some more examples:
|
||||
|
||||
```go-html-template
|
||||
{{/* Rotate the image 90 degrees counter-clockwise. */}}
|
||||
{{ $image := $image.Process "r90" }}
|
||||
|
||||
{{/* Scaling actions. */}}
|
||||
{{ $image := $image.Process "resize 600x" }}
|
||||
{{ $image := $image.Process "crop 600x400" }}
|
||||
{{ $image := $image.Process "fit 600x400" }}
|
||||
{{ $image := $image.Process "fill 600x400" }}
|
||||
```
|
||||
|
||||
|
||||
### Resize
|
||||
|
||||
Resize an image to the specified width and/or height.
|
||||
@@ -477,6 +506,7 @@ hugo --gc
|
||||
[github.com/disintegration/imaging]: <https://github.com/disintegration/imaging#image-resizing>
|
||||
[Smartcrop]: <https://github.com/muesli/smartcrop#smartcrop>
|
||||
[Exif]: <https://en.wikipedia.org/wiki/Exif>
|
||||
[`Process`]: #process
|
||||
[`Colors`]: #colors
|
||||
[`Crop`]: #crop
|
||||
[`Exif`]: #exif
|
||||
|
Reference in New Issue
Block a user