hugo/content/en/functions/images/index.md
Bjørn Erik Pedersen 77b976dd92 Squashed 'docs/' changes from a7e1e9be8..686c7b6eb
686c7b6eb ci(Netlify): specify `HUGO_VERSION` environment variable once
da99a356f fix: change heading level
e57da3f00 Update taxonomy methods
746172490 Update description of rendered breadcrumb navigation
6bc52fd40 Clarify term
dab07dcb0 Fix typo
e50fa452a Fix typo
6c1ea83c2 Update template overview page
a5dc97845 Clarify the append function
a135e52a0 Update GitHub hosting instructions
a51bf9f4f Update sections page
ed35fc6c4 Update archetypes and glossary
1a4522b3e Format examples
a70f20094 Use "hugo new content" to create content
673846ff9 Remove comment
b7febf0c5 Fix link
6f6fe2133 Miscellaneous edits
99227dd18 Remove lookup order table from output formats page
bc8870657 tools/editors: Add Prettier Plugin for Go Templates
157b169eb Update docs.yaml
1c8f514e0 Update cond function
e5f1f8113 Add assumptions to taxonomy and term template lookup order examples
475b406e2 Update postprocess
2d6cb8dfc glossary: Update content type
03b514bac Add descriptions to template lookup order example sections
06678f919 glossary: Fix broken link
4cd505612 Simplify news listing
fadb980db Update glossary of terms
491bacd78 Change order of example sections for template lookup order
04b8f39ec Create glossary of terms
12e896bc0 Remove reference to asciidoctor-rouge extension
055f7bb37 Insert missing words
8cd6ac387 Miscellaneous edits
2cbe17f41 Update configuration.md
529615373 Update data-templates.md
853154e65 Update theme
45f08627a resources.getRemote: Fix definition list
29a51dac1 Update docshelper
3bdfe88c6 Remove link to gitter from site footer
cacd0e461 Use "map" instead of "dictionary"
704dd5da6 Document the transform.Remarshal template function
e8d744951 Populate news section via GitHub releases API
3ff1118c7 Replace docs.json with docs.yaml
7726bbcac Use docs.json to generate default config throughout the site
57dca93df Use docs.json to generate default config for related content
74d5082c7 Add some .RenderShortcodes docs
cf5ab5062 netlify: Hugo 0.117.0
420f7aa69 Add all config to docshelper.json

git-subtree-dir: docs
git-subtree-split: 686c7b6eb182ed335dc94b3a0b80c564f7658380
2023-08-30 19:23:47 +02:00

226 lines
5.5 KiB
Markdown

---
title: Image filters
description: The images namespace provides a list of filters and other image related functions.
categories: [functions]
aliases: [/functions/imageconfig/]
menu:
docs:
parent: functions
keywords: [images]
toc: true
---
See [images.Filter](#filter) for how to apply these filters to an image.
## 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`).
## 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 }}
```