-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Enable transparency for duotone #34130
Conversation
@jasmussen and @mtias This is another instance of wanting to add some additional toggle to duotone, much like posterize. With SVG filters we can do a proper full-color double exposure by using a different Is this something that you think makes sense in core? And if so, what are your thoughts on UI for exposing the feature? |
This is a cool experiment and a cool effect. It seems somewhat tricky to use to get something compelling, given you have to stack a few things, but nevertheless it's nice to know this is possible. For that reason, and for the other SVG filters you mention, I feel like an important next step is to explore how we can evolve the filtering interface to accommodate additional controls (if at all). To me there's still so much potential just in the vanilla duotone feature that we want to tread carefully to not dilute it, and to polish that interface to be its very best. However I'll definitely put on my todo list to explore some mockups for improved filtering. Duotone on its own still needs a little love. Nice one. |
If this is achieved by just setting one of the colors as transparent, it makes sense to just be an effect of using the alpha slider on the color picker, no? (And it wouldn't need extra UI.) |
We discussed this exact thing in a chat very recently, and (correct me if I'm wrong Alex) — for the transparency to work on an image, any image that is already transparent (such as a PNG) will have the transparent parts made black when you apply a duotone filter, up until you leverage the duotone transparency at which point it "starts working" again. Instead of the transparency being something we can toggle on or off to enable this, @ajlende can we just apply the transparency feature only if the alpha transparency is explicitly set to less than 100%? |
@jasmussen is right—that's what I said during our chat. I was thinking that we'd have to add another filter to mask the final output, but I fiddled with some other SVG filter properties this morning in a codepen, and I think I have it working in a single filter. Is there any scenario where we wouldn't want the source alpha to be the final mask for the image? If not, I think I can get this working without needing the switch. |
I can't think of one! If need be you could group the thing and put a background on the group. |
Now that I have the transparency working, I noticed something unexpected when comparing the color/color with the color/transparent images. Notice that the alpha version isn't exactly the same as the color version. I suspect that this is because sRGB mode still treats the alpha channel as linear since it appears generally darker. I don't have a solution for this yet. It may just be a limitation of SVG filters and/or how browsers have them implemented, but more investigation is needed. |
This is wild, I love it 👌 |
I'm not sure if I'm doing something wrong, but my images look quite different:
|
@MaggieCabrera It looks like you have a gradient going from black to transparent white ( Duotone linearly interpolates between all of the channels including the alpha channel, so the lightness you're seeing at the midpoint is actually a 50% transparent 50% gray instead of 50% transparent black. |
Oh, thanks for explaining, that looks much better! |
There are a number of things ongoing duotone:
In that vein, I've done some doodles on how to potentially accommodate that in an upgraded "Filter" menu: There are some aspects of the mockup above that still need some thought, which is why I'm posting it here as a comment to just throw it in a part of the loop. Notably whether it's enough to have the defalt presets act both as presets and as filter types, but also whether the "Edit" button to access advanced configuration is clear enough. |
This is what I see in Safari. Transparency seems to work, which is good. The colors look slightly different because of a webkit bug. However, this bug affects the existing duotone filters as well (see the middle image control as an example), so it shouldn't hold up this PR. |
The new selector uses rgb instead of hex to support transparency for duotone
Conflicts: lib/block-supports/duotone.php packages/block-editor/src/hooks/duotone.js packages/components/src/color-palette/index.js packages/e2e-tests/specs/editor/blocks/heading.test.js
Sorry it took me a while to circle back around on this, but it looks like tests are passing again and it's ready for final review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, and everything tested well for me.
🚀 🌔
Description
Fixes #34121
Adds the ability to set transparency for duotone colors.
Also allows passing through
enableAlpha
for the color picker.How has this been tested?
I used the Skatepark theme colors for the examples below, but I've saved all the colors as custom colors, so they should appear the same regardless of the theme you are using.
Screenshots
Match background
This example shows three different ways that transparency can be applied with duotone. The first and last show a transparent value in use for the duotone filter, and the middle one shows a png with transparency. Code is below to try it out yourself.
Image Layering
In an advanced use-case, you could overlay a transparent duotone image on top of another image. Some might call this a "double exposure" effect, but it's not quite the same since we're not using full-color images. It's also a bit like an image mask, but you're not letting the background show through; you're just letting the image obscure some parts of the image below it.
Olly Moss has some cool examples of something that could be achieved with layered transparent duotone. In the images below, the tan/cream outline could be one duotone image "masking" the contents. In this specific example, because the background of the composition incorporates elements that need specific positioning to complete the effect, this exact composition is probably more suited for editing in Photoshop than WordPress, but it could theoretically be achieved in WordPress with this change.
Using the two images below, we can create our own "double exposure" effect. I just grabbed a couple of CC0-licensed images, but choosing a better image mask could make for a better composition.
Types of changes
New feature
Checklist:
*.native.js
files for terms that need renaming or removal).