-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Image Block: Add "circle" style #16130
Comments
This would be super groovy. Note that we can apply this style with CSS, but we'll probably also want to do some cropping in the case of images that aren't square, because whilst a circle image is pretty, an oval image is deeply ugly. |
I tried a circle crop variation in https://github.com/WordPress/gutenberg/tree/try/circle-crop-variation because I agree, that is super groovy. Given the age of the branch, I obviously came up short, but hopefully it can serve as inspiration to someone more skilled than me. I recall the primary problem being to create a perfect square of an arbitrarily sized image (necessary for a perfect circle), yet still allow it to be resized using the ResizableBox component. |
Idea that might enable this: surface object fit in the sidebar as something you can configure on per-image basis. When an image has |
If in any case anyone is looking for a solution right now, I've added "Circular" Styles on Cover and Image Block to EditorsKit plugin. Here's the link where you can download the free plugin : https://wordpress.org/plugins/block-options/ and here's the link to the preview alongside other available styles : https://twitter.com/phpbits/status/1145668037598539777 I've also used |
Thanks for sharing, @phpbits!
This is how that works in action: That's actually a kind of creative solution. You avoid that nasty oval shape that you'd get with Would you mind if I took inspiration from your trick to submit a circle crop PR to Gutenberg itself? I'll give you props in the commit, of course! |
@jasmussen Sure thing! No problem here :) Here's my code on the block styles : https://github.com/phpbits/block-options/tree/master/src/extensions/block-styles . Let me know if you need anything and will be very happy to help out. Cheers! |
That's awesome, thank you. I'll CC you on the PR. |
Thanks again. Created a PR here: #16475 |
From @sarahmonster
I fiercely agree. This is what blocked me from the other approach. However as I worked on this, I realized you can choose the image source from the block inspector and for example choose thumbnail which by default is square. Or you could make larger thumbnail presets that were also square and choose the crop there. What do you think about using that as the solution to square-from-rectangles? |
❤️❤️❤️ I would definitely be a fan of that approach. I think* (assumption, might be wrong) that users would expect, when selecting "circle" from block styles, the image to show up as a circle, regardless of the proportions of the originally uploaded image. As a user, I don't necessarily want to spend a lot of time fussing with proportions and worrying whether my crop is perfect or not—I just want it to work. |
Do you think there is a rephrasing that would allow us to more or less accomplish the same? Edit: such as "Rounded". Technically it would let you accomplish the same as is asked for in the ticket, just in a generic way. |
Is there maybe a use case for two different variants/behaviours entirely here? Circle = crop image + turn it into a perfect circle (especially good for profiles and avatars) This could be particularly nice if we then allowed the border-radius to be fine-tuned by the user—although I think that might be best left as a theme option, because I'd hate to see a site with 8px corners on one page and 10px corners on another. |
I do very much agree on both accounts. The primary benefit of the "rounded" variation is that it uses existing UI (block switcher style variations), very simple CSS, and by choosing the source file from the block settings sidebar, you can choose which crop you'd like based on what WordPress created for you when you uploaded the file. If we actually have to hard-crop when selecting the image, it's a much bigger undertaking. In the past I tried my very best to "soft crop", i.e. make the image be square using only CSS — but I just couldn't get that to work. |
Ahh I see—I think I may have misunderstood here. I thought we could just programmatically grab the square-cropped image, and use that. 😢 It sounds like the best approach is to go with the rounded corners option then, and maybe just call the style variant "Rounded" or similar? It implies that the shape could be a circle, but still acts as a descriptor in the case where your shape winds up being a not-circle. |
Joining into this a little late, but an alternate option would be to try using a CSS mask. This keeps things square and circular, and would theoretically only require a tiny bit of CSS. The only real downside I see is that it doesn't work in IE. Here's a demo: |
^ This is exactly what I'd hope for! |
That is pretty gosh darn killer, Kjell! I did not know that was possible. It's worth noting that in the editor you will still see resize handles "floating in space", as they still align to the actual boundaries of the image. However your solution checks the boxes:
The fact that it doesn't work in IE11 is probably okay — can we do something like add the rounded border radius from my PR, and then use an I feel like I owe you a milkshake or something. Would you like to commandeer my PR in #16475? It has all the base ingredients to add a style variation to the image block called circle — "all" you'd need to do is add your clipping path instead. Edit: Oh I guess if you float the image, there will also still be sort of an invisible margin from the boundaries of the image, which you can't actually do anything about. That may actually be kind of a bummer. |
I posted the code for this here. The inline SVG there fails our listing tests, so it needs a little bit of troubleshooting. |
Yeah, this is the main downside to the |
Could a focal point picker fix that? |
Not exactly — the issue is more about the dimensions of the image. We aren't really cropping here, we're just adding circular overlay. So the image is still rectangular, it's just that the area outside of the image is transparent and takes up space still. |
Yes, well this is sort of the same issue my initial approach had, and you can fix it in the same way: pick a square source image from the sidebar. And also, this variation does not preclude us from running with having a "pill shape" variation too. I don't necessarily think it's a blocker, though I do wonder if those invisible margins will be harder for a user to understand, than the pill shape. |
While testing in Twenty Eleven, I noticed that Edge does not display the rectangular images properly. Edge apparently supports The rectangles can have a pill shape instead by adding this Edge-specific condition:
|
Should we close this issue now @jasmussen? |
So, I actually regret what we ended up with here :| The fact that the resize handles float in the air and the actual width of the image is unchanged makes for a bad experience. also with long captions that still go to the full width of the image: You can't float the image left and have text wrap around it because there will be arbitrary margins left and right. You can't put several of them in sequence. So it is misleading and not that useful. I think we should revert the circular CSS mask and go back to a "pill shape", the one with border-radius: 9999px. Then you can still have a perfect circle if you actually crop the image to a square, but the style will still be useful for images that are not square. |
I had this come up with a user in chat today. They were using the theme Rockfield and had 4 images where 2 were displaying properly as circles and 2 were not. The 2 images that were styling differently were rectangular images. The user re-uploaded as squares and the issue was resolved. Site is: https://laboratoirevisuel.ca/ |
Fixes #16130, notably a followup to the issue outlined in #16130 (comment). The "circle mask" variation has the benefit of creating a perfect circle out of any shape image. However it doesn't change the dimensions of the image, so the tradeoff is that the image footprint is still large, and resize handles now float in air. This PR changes it to a "rounded" style, which sets a very high border radius ensuring that the smallest sides on a rectangular image are perfectly rounded, creating a pill-shape. When the image is perfectly square, the variation will be perfectly circular. This ensures that the variation is useful both when images are rectangular, it ensures the resize handles are appropriately placed, it fixes an issue where Microsoft Edge did not render the mask properly, and it indicates to the user that if they want a perfect circle, they can upload a square image, or change the dimensions in the sidebar.
* Image Block: Revert circle mask, add "rounded" Fixes #16130, notably a followup to the issue outlined in #16130 (comment). The "circle mask" variation has the benefit of creating a perfect circle out of any shape image. However it doesn't change the dimensions of the image, so the tradeoff is that the image footprint is still large, and resize handles now float in air. This PR changes it to a "rounded" style, which sets a very high border radius ensuring that the smallest sides on a rectangular image are perfectly rounded, creating a pill-shape. When the image is perfectly square, the variation will be perfectly circular. This ensures that the variation is useful both when images are rectangular, it ensures the resize handles are appropriately placed, it fixes an issue where Microsoft Edge did not render the mask properly, and it indicates to the user that if they want a perfect circle, they can upload a square image, or change the dimensions in the sidebar. * Add back-compat.
[gallery ids="4415" type="circle" columns="1"] This worked for me in 2020 but not in 2021. |
Is your feature request related to a problem? Please describe.
I keep running into cases where I'm combining image, heading, and paragraph blocks to make "teams" and "testimonials" and "endorsements" and whatnot, but I want the images to all be circles instead of squares or rectangles. It would be good to add a "circle" style to all image blocks.
Describe alternatives you've considered
Using CSS to mask the images, but this is a pain.
The text was updated successfully, but these errors were encountered: