mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-16 12:54:42 -04:00
Add images.Process filter
This allows for constructs like: ``` {{ $filters := slice (images.GaussianBlur 8) (images.Grayscale) (images.Process "jpg q30 resize 200x") }} {{ $img = $img | images.Filter $filters }} ``` Note that the `action` option in `images.Process` is optional (`resize` in the example above), so you can use the above to just set the target format, e.g.: ``` {{ $filters := slice (images.GaussianBlur 8) (images.Grayscale) (images.Process "jpg") }} {{ $img = $img | images.Filter $filters }} ``` Fixes #8439
This commit is contained in:
parent
5736458830
commit
918ed53f49
@ -12,6 +12,28 @@ toc: true
|
|||||||
|
|
||||||
See [images.Filter](#filter) for how to apply these filters to an image.
|
See [images.Filter](#filter) for how to apply these filters to an image.
|
||||||
|
|
||||||
|
## Process
|
||||||
|
|
||||||
|
{{< new-in "0.119.0" >}}
|
||||||
|
|
||||||
|
{{% funcsig %}}
|
||||||
|
images.Overlay SRC SPEC
|
||||||
|
{{% /funcsig %}}
|
||||||
|
|
||||||
|
A general purpose image processing function.
|
||||||
|
|
||||||
|
This filter has all the same options as the [Process](/content-management/image-processing/#process) method, but using it as a filter may be more effective if you need to apply multiple filters to an image:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $filters := slice
|
||||||
|
images.Grayscale
|
||||||
|
(images.GaussianBlur 8)
|
||||||
|
(images.Process "resize 200x jpg q30")
|
||||||
|
}}
|
||||||
|
{{ $img = $img | images.Filter $filters }}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Overlay
|
## Overlay
|
||||||
|
|
||||||
{{% funcsig %}}
|
{{% funcsig %}}
|
||||||
@ -36,6 +58,8 @@ The above will overlay `$logo` in the upper left corner of `$img` (at position `
|
|||||||
|
|
||||||
## Opacity
|
## Opacity
|
||||||
|
|
||||||
|
{{< new-in "0.119.0" >}}
|
||||||
|
|
||||||
{{% funcsig %}}
|
{{% funcsig %}}
|
||||||
images.Opacity SRC OPACITY
|
images.Opacity SRC OPACITY
|
||||||
{{% /funcsig %}}
|
{{% /funcsig %}}
|
||||||
@ -47,6 +71,15 @@ The OPACITY parameter must be in range (0, 1).
|
|||||||
{{ $img := $img.Filter (images.Opacity 0.5 )}}
|
{{ $img := $img.Filter (images.Opacity 0.5 )}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that target format must support transparency, e.g. PNG. If the source image is e.g. JPG, the most effective way would be to combine it with the [`Process`] filter:
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ $png := $jpg.Filter
|
||||||
|
(images.Opacity 0.5)
|
||||||
|
(images.Process "png")
|
||||||
|
}}
|
||||||
|
```
|
||||||
|
|
||||||
## Text
|
## Text
|
||||||
|
|
||||||
Using the `Text` filter, you can add text to an image.
|
Using the `Text` filter, you can add text to an image.
|
||||||
@ -237,3 +270,5 @@ images.ImageConfig PATH
|
|||||||
favicon.ico: {{ .Width }} x {{ .Height }}
|
favicon.ico: {{ .Width }} x {{ .Height }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[`Process`]: #process
|
Loading…
x
Reference in New Issue
Block a user