hugo/content/en/functions/images/index.md
Bjørn Erik Pedersen e509cac533 Squashed 'docs/' changes from 7ef2dbce4..cb18a5183
cb18a5183 Fix broken link
07a0198bf Config: Place Google Analytics tag ID under the services key
4bf0c719f Fix typo
50d8ad1af Fix muiltilingual menu definition instructions
1a32519a9 Fix typos
6f34ca8e0 Explain usage of front matter to target a template
5bd977257 Improve goldmark config docs
447632938 Remove Docker notes from installation instructions
84741d173 Update reference to hugo.work
0338d7c71 Fix menu template
f5d2f5ed4 Fix typos in content/en/functions/fmt
a3a40ff99 Add return type to functions
85ac3e779 Remove outdated feature image
d47d889e4 Fix signatures
7551ba28f Document safe.JSStr function
e77993be0 Document keyVals function
4dba20db3 Update theme
babf91544 Update echoparam
8c8203efa Adjust related functions
4cb1b30fc Fix example
ba95eca64 Improve showcase prose
5d3dcf366 Add Overmind Studios showcase
8d634ac70 Change code blocks from indented to fenced
cfab978e6 Add missing code fences
407dd5c47 Limit related pages for functions to other functions
9fa67d981 Fix .Site.LastChange doc
393aa16d0 netlify: Hugo 0.119.0
f864af97a docs: Even more about images.Process
9d772d5f0 docs: More about images.Process
bc655f869 docs: Regen docshelper
41c3536d1 Merge commit '9aec42c5452b3eb224888c50ba1c3f3b68a447e9'
918ed53f4 Add images.Process filter
573645883 Add $image.Process
a1151b0fd Add images.Opacity filter

git-subtree-dir: docs
git-subtree-split: cb18a5183fc62f301ffde50b8c39f03e4b897aec
2023-10-20 09:42:39 +02:00

274 lines
6.6 KiB
Markdown

---
title: Image filters
description: The images namespace provides a list of filters and other image related functions.
categories: [functions]
keywords: []
aliases: [/functions/imageconfig/]
menu:
docs:
parent: functions
keywords: [images]
toc: true
---
See [images.Filter](#filter) for how to apply these filters to an image.
## Process
{{< new-in "0.119.0" >}}
{{% funcsig %}}
images.Process 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
{{% funcsig %}}
images.Overlay SRC X Y
{{% /funcsig %}}
Overlay creates a filter that overlays the source image at position x y, e.g:
```go-html-template
{{ $logoFilter := (images.Overlay $logo 50 50 ) }}
{{ $img := $img | images.Filter $logoFilter }}
```
A shorter version of the above, if you only need to apply the filter once:
```go-html-template
{{ $img := $img.Filter (images.Overlay $logo 50 50 )}}
```
The above will overlay `$logo` in the upper left corner of `$img` (at position `x=50, y=50`).
## Opacity
{{< new-in "0.119.0" >}}
{{% funcsig %}}
images.Opacity SRC OPACITY
{{% /funcsig %}}
Opacity creates a filter that changes the opacity of an image.
The OPACITY parameter must be in range (0, 1).
```go-html-template
{{ $img := $img.Filter (images.Opacity 0.5 )}}
```
This filter is most useful for target formats that 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
Using the `Text` filter, you can add text to an image.
{{% funcsig %}}
images.Text TEXT MAP)
{{% /funcsig %}}
The following example will add the text `Hugo rocks!` to the image with the specified color, size and position.
```go-html-template
{{ $img := resources.Get "/images/background.png" }}
{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict
"color" "#ffffff"
"size" 60
"linespacing" 2
"x" 10
"y" 20
))}}
```
You can load a custom font if needed. Load the font as a Hugo `Resource` and set it as an option:
```go-html-template
{{ $font := resources.GetRemote "https://github.com/google/fonts/raw/main/apache/roboto/static/Roboto-Black.ttf" }}
{{ $img := resources.Get "/images/background.png" }}
{{ $img = $img.Filter (images.Text "Hugo rocks!" (dict
"font" $font
))}}
```
## Brightness
{{% funcsig %}}
images.Brightness PERCENTAGE
{{% /funcsig %}}
Brightness creates a filter that changes the brightness of an image.
The percentage parameter must be in range (-100, 100).
### ColorBalance
{{% funcsig %}}
images.ColorBalance PERCENTAGERED PERCENTAGEGREEN PERCENTAGEBLUE
{{% /funcsig %}}
ColorBalance creates a filter that changes the color balance of an image.
The percentage parameters for each color channel (red, green, blue) must be in range (-100, 500).
## Colorize
{{% funcsig %}}
images.Colorize HUE SATURATION PERCENTAGE
{{% /funcsig %}}
Colorize creates a filter that produces a colorized version of an image.
The hue parameter is the angle on the color wheel, typically in range (0, 360).
The saturation parameter must be in range (0, 100).
The percentage parameter specifies the strength of the effect, it must be in range (0, 100).
## Contrast
{{% funcsig %}}
images.Contrast PERCENTAGE
{{% /funcsig %}}
Contrast creates a filter that changes the contrast of an image.
The percentage parameter must be in range (-100, 100).
## Gamma
{{% funcsig %}}
images.Gamma GAMMA
{{% /funcsig %}}
Gamma creates a filter that performs a gamma correction on an image.
The gamma parameter must be positive. Gamma = 1 gives the original image.
Gamma less than 1 darkens the image and gamma greater than 1 lightens it.
## GaussianBlur
{{% funcsig %}}
images.GaussianBlur SIGMA
{{% /funcsig %}}
GaussianBlur creates a filter that applies a gaussian blur to an image.
## Grayscale
{{% funcsig %}}
images.Grayscale
{{% /funcsig %}}
Grayscale creates a filter that produces a grayscale version of an image.
## Hue
{{% funcsig %}}
images.Hue SHIFT
{{% /funcsig %}}
Hue creates a filter that rotates the hue of an image.
The hue angle shift is typically in range -180 to 180.
## Invert
{{% funcsig %}}
images.Invert
{{% /funcsig %}}
Invert creates a filter that negates the colors of an image.
## Pixelate
{{% funcsig %}}
images.Pixelate SIZE
{{% /funcsig %}}
Pixelate creates a filter that applies a pixelation effect to an image.
## Saturation
{{% funcsig %}}
images.Saturation PERCENTAGE
{{% /funcsig %}}
Saturation creates a filter that changes the saturation of an image.
## Sepia
{{% funcsig %}}
images.Sepia PERCENTAGE
{{% /funcsig %}}
Sepia creates a filter that produces a sepia-toned version of an image.
## Sigmoid
{{% funcsig %}}
images.Sigmoid MIDPOINT FACTOR
{{% /funcsig %}}
Sigmoid creates a filter that changes the contrast of an image using a sigmoidal function and returns the adjusted image.
It's a non-linear contrast change useful for photo adjustments as it preserves highlight and shadow detail.
## UnsharpMask
{{% funcsig %}}
images.UnsharpMask SIGMA AMOUNT THRESHOLD
{{% /funcsig %}}
UnsharpMask creates a filter that sharpens an image.
The sigma parameter is used in a gaussian function and affects the radius of effect.
Sigma must be positive. Sharpen radius roughly equals 3 * sigma.
The amount parameter controls how much darker and how much lighter the edge borders become. Typically between 0.5 and 1.5.
The threshold parameter controls the minimum brightness change that will be sharpened. Typically between 0 and 0.05.
## Other Functions
### Filter
{{% funcsig %}}
IMAGE | images.Filter FILTERS...
{{% /funcsig %}}
Can be used to apply a set of filters to an image:
```go-html-template
{{ $img := $img | images.Filter (images.GaussianBlur 6) (images.Pixelate 8) }}
```
Also see the [Filter Method](/content-management/image-processing/#filter).
### ImageConfig
Parses the image and returns the height, width, and color model.
The `imageConfig` function takes a single parameter, a file path (_string_) relative to the _project's root directory_, with or without a leading slash.
{{% funcsig %}}
images.ImageConfig PATH
{{% /funcsig %}}
```go-html-template
{{ with (imageConfig "favicon.ico") }}
favicon.ico: {{ .Width }} x {{ .Height }}
{{ end }}
```
[`Process`]: #process