Skip to content
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 orientation (portrait vs landscape) aware transformations for w, h and aspect #749

Open
clemdee opened this issue Sep 27, 2024 · 1 comment

Comments

@clemdee
Copy link

clemdee commented Sep 27, 2024

I find myself in a situation where I have both landscape and portrait images (loaded via import.meta.glob), and I want to resize them so that their larger side do not exceed 1000px, and also ensure a 16/9 aspect ratio in their respective orientation.

Currently, this is not possible to do, as we only have w and h directives, and aspect-ratio is independent from orientation.

I can see two solutions for this:

minSide, maxSide and orientedAspect

In a similar idea to vmin / vmax css units, corresponding to the smaller / larger size between vh and vw, we could have here two new directives: minSide and maxSide, allowing to set the size of the smaller / larger side of the image.

We would in addition have a new orientedAspect, that would perform the aspect ratio taking into consideration the image orientation.

It would be used like the following:

import Image from 'example.jpg?maxSide=1000'
import Image from 'example.jpg?minSide=640&orientedAspect=16:9'

These names can be bikeshedded if needed.

orientationAware

Instead of introducing a new directive for each directive that is sensitive to image orientation, we could instead just introduce a single one, specifying how to apply these transforms based on the image orientation.

So when the orientationAware directive is specified, the image is always handled as if in landscape mode:

  • w resizes the larger side
  • h resizes the smaller side
  • aspect is in the format large:small

It would be used like the following:

import Image from 'example.jpg?orientationAware&w=1000'
import Image from 'example.jpg?orientationAware&h=640&aspect=16:9'

Likewise, the directive name can probably be changed to something more desirable.


Do you have an opinion about the preferred approach?

@clemdee
Copy link
Author

clemdee commented Sep 27, 2024

seems related: #722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant