diff --git a/content/en/content-management/shortcodes.md b/content/en/content-management/shortcodes.md index 7f1025fa4..32ebb9ba6 100644 --- a/content/en/content-management/shortcodes.md +++ b/content/en/content-management/shortcodes.md @@ -416,31 +416,39 @@ The youtube shortcode accepts these named parameters: id : (`string`) The video `id`. Optional if the `id` is provided as a positional argument as shown in the example above. -allowFullScreen {{< new-in 0.125.0 >}} +allowFullScreen +{{< new-in 0.125.0 >}} : (`bool`) Whether the `iframe` element can activate full screen mode. Default is `true`. -autoplay {{< new-in 0.125.0 >}} +autoplay + {{< new-in 0.125.0 >}} : (`bool`) Whether to automatically play the video. Forces `mute` to `true`. Default is `false`. class : (`string`) The `class` attribute of the wrapping `div` element. When specified, removes the `style` attributes from the `iframe` element and its wrapping `div` element. -controls {{< new-in 0.125.0 >}} +controls +{{< new-in 0.125.0 >}} : (`bool`) Whether to display the video controls. Default is `true`. -end {{< new-in 0.125.0 >}} +end +{{< new-in 0.125.0 >}} : (`int`) The time, measured in seconds from the start of the video, when the player should stop playing the video. -loading {{< new-in 0.125.0 >}} +loading +{{< new-in 0.125.0 >}} : (`string`) The loading attribute of the `iframe` element, either `eager` or `lazy`. Default is `eager`. -loop {{< new-in 0.125.0 >}} +loop +{{< new-in 0.125.0 >}} : (`bool`) Whether to indefinitely repeat the video. Ignores the `start` and `end` arguments after the first play. Default is `false`. -mute {{< new-in 0.125.0 >}} +mute +{{< new-in 0.125.0 >}} : (`bool`) Whether to mute the video. Always `true` when `autoplay` is `true`. Default is `false`. -start {{< new-in 0.125.0 >}} +start +{{< new-in 0.125.0 >}} : (`int`) The time, measured in seconds from the start of the video, when the player should start playing the video. title diff --git a/content/en/methods/resource/Colors.md b/content/en/methods/resource/Colors.md index 1452d558f..6516045cd 100644 --- a/content/en/methods/resource/Colors.md +++ b/content/en/methods/resource/Colors.md @@ -5,18 +5,173 @@ categories: [] keywords: [] action: related: [] - returnType: '[]string' + returnType: '[]images.Color' signatures: [RESOURCE.Colors] +toc: true +math: true --- {{< new-in 0.104.0 >}} +The `Resources.Colors` method returns a slice of the most dominant colors in an image, ordered from most dominant to least dominant. This method is fast, but if you also downsize your image you can improve performance by extracting the colors from the scaled image. + +{{% include "methods/resource/_common/global-page-remote-resources.md" %}} + +## Methods + +Each color is an object with the following methods: + +ColorHex +{{< new-in 0.125.0 >}} +: (`string`) Returns the [hexadecimal color] value, prefixed with a hash sign. + +Luminance +{{< new-in 0.125.0 >}} +: (`float64`) Returns the [relative luminance] of the color in the sRGB colorspace in the range [0, 1]. A value of `0` represents the darkest black, while a value of `1` represents the lightest white. + +{{% note %}} +Image filters such as [`images.Overlay`] and [`images.Padding`] will accept either a hexadecimal color value or an `images.Color` object. + +Hugo renders an `images.Color` object as a hexadecimal color value. + +[`images.Overlay`]: /functions/images/overlay/ +[`images.Padding`]: /functions/images/padding/ +{{% /note %}} + +[hexadecimal color]: https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color +[relative luminance]: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance + +## Sorting + +As a contrived example, create a table of an image's dominant colors with the most dominant color first, and display the relative luminance of each dominant color: + ```go-html-template {{ with resources.Get "images/a.jpg" }} - {{ .Colors }} → [#bebebd #514947 #768a9a #647789 #90725e #a48974] +
| Color | +Relative luminance | +
|---|---|
| {{ .ColorHex }} | +{{ .Luminance | lang.FormatNumber 4 }} | +
This is light text on a dark background.
+