| 1 |
--- |
| 2 |
title: images.Opacity |
| 3 |
description: Returns an image filter that changes the opacity of an image. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: images.filter |
| 10 |
signatures: [images.Opacity OPACITY] |
| 11 |
--- |
| 12 |
|
| 13 |
The opacity value must be in the range [0, 1]. A value of `0` produces a transparent image, and a value of `1` produces an opaque image (no transparency). |
| 14 |
|
| 15 |
## Usage |
| 16 |
|
| 17 |
Create the filter: |
| 18 |
|
| 19 |
```go-html-template |
| 20 |
{{ $filter := images.Opacity 0.65 }} |
| 21 |
``` |
| 22 |
|
| 23 |
{{% include "/_common/functions/images/apply-image-filter.md" %}} |
| 24 |
|
| 25 |
The `images.Opacity` filter is most useful for target formats such as AVIF, PNG, and WebP that support transparency. If the source image does not support transparency, combine this filter with the `images.Process` filter: |
| 26 |
|
| 27 |
```go-html-template |
| 28 |
{{ with resources.Get "images/original.jpg" }} |
| 29 |
{{ $filters := slice |
| 30 |
(images.Opacity 0.65) |
| 31 |
(images.Process "png") |
| 32 |
}} |
| 33 |
{{ with . | images.Filter $filters }} |
| 34 |
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> |
| 35 |
{{ end }} |
| 36 |
{{ end }} |
| 37 |
``` |
| 38 |
|
| 39 |
## Example |
| 40 |
|
| 41 |
{{< img |
| 42 |
src="images/examples/zion-national-park.jpg" |
| 43 |
alt="Zion National Park" |
| 44 |
filter="Opacity" |
| 45 |
filterArgs="0.65" |
| 46 |
example=true |
| 47 |
>}} |