-
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
Image block: Implement aspect ratio control #51138
Comments
In order to use the same dropdown we had in the Featured Image block, I think 'Custom' will have to be an option from the beginning. I can probably auto-fill the width/height controls when it is selected if that's okay. For example, if square ratio is selected and width is 100, then selecting custom will set height to be 100. If both are auto, then it can use the values from the intrinsic width and height. @richtabor does that seem reasonable to you? |
One problem I see with doing this is that I'd expect to be able to set the custom aspect ratio and let the image fill the wide width or something, for example. Unfortunately, that won't be possible because the width and height have units. Likewise, if I wanted the image to be 50% width and 16:10 (custom) aspect ratio, that isn't possible. |
I'd say 'classic' makes me think 3:2 instead of 4:3. Not sure why we chose 4:3 for the cropping tool, but since we're already diverging from that, maybe we could use 3:2 instead here? |
I think that's fine. The alternative is to set the image in a row/column and use that as the bounding element (which is what most folks do with layouts/patterns that include images anyhow). |
Does that mean the meaning of width/height changes if you have an aspect ratio selected? i.e. When aspect ratio is 'Original' the width and height set, |
Even if it gets automatically selected when you set both width and height, 'custom' has to be part of the list. And to be clear, 'original' would still need to exist as an option too–it has a different meaning from 'custom'. |
If width and height are both set, does the aspect ratio select become disabled? If so, do you think it will be clear that deleting one of the widths or heights is the way to make it not disabled? Or if not, what should happen when one of the other aspect ratios is selected? |
Yes, "custom" uses the height/width attributes to define the aspect ratio.
Good point. I'd almost want it to be labeled "Freeform".
No, if height and width are set, then aspect ratio should be "custom" and the height/width are used as the aspect ratio CSS. That way I could drop in a new image and maintain the aspect ratio, re #38990 (comment).
If I change from a custom/freeform aspect ratio to a defined ratio, like square, then we should keep the width and reset height to auto - to employ the aspect ratio. What do you think of that? |
Thanks for the answers!
Brainstorming ideas here to make it clear that the width and height controls change their meaning. Maybe it could be something like "Use width/height for aspect ratio"? That seems a bit long, but I worry, as it is, that there could be some confusion around what width/height do.
👍 |
I think it's clear enough that "Custom" will use the height/width values. It's also more likely "custom" is applied when the height and width have been changed (instead of selecting it from the Select). We can follow-up with additional descriptive text perhaps, if custom is selected; not a blocker imo though. |
@richtabor I'm struggling again with the details of custom ratios as I've been trying to implement this. At the moment, the image block dimensions represent pixel values, but in many other places, like the post featured image block, the fields include selectable units. I see units in your design, and I'd rather not add a second implementation for aspect ratio specific to the image block, so I'd like to add units to the image block as part of my PR. There are three problems that I'm running into while I'm trying to do this.
Problems 1 & 3 could be solved by creating a second implementation for the image block, but eventually we're going to want to use the same implementation in all places—it's just postponing the problem and adding additional complexity with deprecations and backwards compatibility. |
We shouldn't need to make the image full width/wider — just use the intrinsic width value. If I upload an image that is 800px wide, and select 1:1 aspect ratio, it would be 800x800px. |
Let's say I upload an image with a resolution of 3840x2160px. In the editor, I changed the width to be 800px so it isn't so wide on the page. Then I select 1:1 aspect ratio. Now the size of the image is 3840x3840px on the page, not the 800px that I want it to be. |
The css changes from height: auto;
max-width: 100%;
width: 800px; to height: auto;
max-width: 100%;
aspect-ratio: 1; if the meaning of the height and width controls is supposed to represent an aspect ratio. |
When you do this, please also closely observe these aspects:
|
WordPress.Image.Block.1.drag.handles.resize.proportionally.mp4WordPress.Image.Block.2.numerical.input.resizes.not.proportionally.mp4WordPress.Image.Block.3.numerical.input.sometimes.resizes.proportionally.mp4 |
@porg Thanks for taking the time to make some videos. I'll keep them in mind when working on this, but dragging and modifier keys are related to the |
@richtabor I think I was just confused earlier by the units disappearing in the design. After coming back to this after a break I think what you intended was having the width/height controls always control the The "Custom" aspect ratio shouldn't actually create a custom aspect ratio, and it probably doesn't even need to set the |
As long as the aspect ratio is unset if both height and width are changed. |
Is there any way to filter gutenberg image block aspect ratio, I want to add my custom aspect ratio (5/4) |
@AhmadRaza9 check out the latest WordPress developer post on adding custom aspect ratios: https://developer.wordpress.org/news/2024/08/05/registering-custom-aspect-ratios-in-wordpress-6-6/ |
Based on the design explorations in #38990, let's implement the aspect ratio control for the
core/image
block.Visual
Figma Prototype
Objective
If I have an aspect ratio applied to an Image block with a set height and width, I should be able to drop in another image and the aspect ratio, height, and width values are all maintained.
Tasks
Follow-up
The text was updated successfully, but these errors were encountered: