-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebP contrast issues #102
Comments
A (very dirty) workaround, if you really need to use WebP images: --- a/layouts/partials/gallery.html
+++ b/layouts/partials/gallery.html
@@ -25,6 +25,7 @@
"Date" $date
"image" $image
"Params" $image.Params
+ "MediaType" $image.MediaType
)
}}
{{ end }}
@@ -32,6 +33,12 @@
{{ $image := .image }}
{{ $thumbnail := $image.Filter (slice images.AutoOrient (images.Process "fit 600x600")) }}
{{ $full := $image.Filter (slice images.AutoOrient (images.Process "fit 1600x1600")) }}
+ {{ /* Workaround for WebP contrast issues: https://github.com/nicokaiser/hugo-theme-gallery/issues/102 */}}
+ {{ if eq $image.MediaType.SubType "webp" }}
+ {{ $thumbnail = $image.Filter (slice images.AutoOrient (images.Process "fit 600x600") (images.Contrast +13)) }}
+ {{ $full = $image.Filter (slice images.AutoOrient (images.Process "fit 1600x1600") (images.Contrast +13)) }}
+ {{ end }}
{{ $color := index $thumbnail.Colors 0 | default "transparent" }}
<a class="gallery-item" href="{{ $image.RelPermalink }}" data-pswp-src="{{ $full.RelPermalink }}" data-pswp-width="{{ $full.Width }}" data-pswp-height="{{ $full.Height }}" data-pswp-target="{{ $image.Name | urlize }}" title="{{ .Title }}" itemscope itemtype="https://schema.org/ImageObject" style="aspect-ratio: {{ $thumbnail.Width }} / {{ $thumbnail.Height }}">
<figure style="background-color: {{ $color }}; aspect-ratio: {{ $thumbnail.Width }} / {{ $thumbnail.Height }}"> This adds 13% contrast to WebP image (which is roughly the level difference between limited an full color range. Note that this might not work for all WebP images and may result in wrong colors. |
nicokaiser
added a commit
that referenced
this issue
Dec 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Due to a bug in the WebP library used in Hugo (as of version 0.139) black and white levels in WebP images are not handled correctly, which makes the images look more dull/muted.
There seems to be no workaround other than either the bug to be fixed or Hugo moving to another WebP library, so my recommendation is not to use WebP images in Hugo.
The text was updated successfully, but these errors were encountered: