-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Adding image masking feature via resources/images/filter.go and mask.go #13106
base: master
Are you sure you want to change the base?
Conversation
What's the practical use case(s) for this in a Hugo site? |
@jmooring what do you think about this? It's obviously useful, but I'm debating about whether this may be better to do in CSS, e.g. https://www.w3schools.com/css/css3_masking.asp |
But every new knob in Hugo comes at a cost. |
Here's a before and after example with the background color of the code to generate the above
So the masking part works, but I think it might be more useful if you could set the canvas color. This would be expressed as an RGB or RGBA hexadecimal color, with a default value of Please don't spend any time implementing the canvas color option until this proposal is accepted. It's a nice addition to the filter collection, but I have no idea if anyone will use it. |
@trickkiste OK; let's add this, but we need an optional {{ $pathBase := "images/original.jpg" }}
{{ $pathMask := "images/mask.png" }}
{{ with resources.Get $pathMask }}
{{ $opts := dict "color" "#ffffff00" }}
{{ $filter := images.Mask . $opts }}
{{ with resources.Get $pathBase }}
{{ with . | images.Filter $filter }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ else }}
{{ errorf "Unable to get resource %q" $pathBase }}
{{ end }}
{{ else }}
{{ errorf "Unable to get resource %q" $pathMask }}
{{ end }} Also, could you add a new Markdown page to the I will add a basic test as part of #13129 |
Hi there,
I have added an image masking feature to the HUGO image filter stack.
It takes a grayscale mask image (or interprets a color image as such), where black indicates which sections of the base image should become transparent and white the opaque sections.
The mask is resized to the size of the base image. If anybody has a need for applying masks without resizing, please propose how to add such a switch.
Here is an example on how to use this feature:
Here is a sample mask image:
Thank you for your feedback or at best inclusion of my patch.
My kind regards
Markus