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

Correct fluid image cropping: both maxHeight and maxWidth #21870

Closed
wants to merge 4 commits into from
Closed

Correct fluid image cropping: both maxHeight and maxWidth #21870

wants to merge 4 commits into from

Conversation

benedictjohannes
Copy link

These PR commits improve fluid image cropping.

In this PR:

  • Correct presentationHeight reported when both maxHeight and maxWidth is set.
  • Correct base64 image aspect ratio
  • Details sizing on fluid cropping to the plugin documentation
  • On my rather simplified testing, the tracedSVG aspect ratio also gets corrected. (I didn't expect this).

details

Current, when both maxHeight and maxWidth is set, the image is cropped cropped to an aspect ratio of maxHeight and maxWidth, but base64 and tracedSVG is not cropped, and presentationWidth follows maxWidth but presentationHeight is calculated from original image propoortion.

While behavior is undocumented/unexpected, this allows image cropping while maintaining fluid image characteristics, that is very useful in cases like responsive hero image sliders.

These corrections help to address #11851, add documentation (helps #12972) and in my tests help #12008

If current behavior of cropping should be optional as this comment specifies, a simple option such as disableCrop should be simple to implement.

This is my first attempt on contributing to open source, please help advice.

Fluid function crops image with aspect ratios when both maxWidth and maxHeight is set.
This behavior is currently not documented, but desirable as it allows cropping image while retaining fluid image characteristics.
However, presentationHeight is calculated only from original height, not maxHeight if specified, leading to incorrect presentationHeight.
This commit corrects it.
make fluid base64 images cropped when botth `maxWidth` and `maxHeight` is set
@benedictjohannes benedictjohannes requested review from a team as code owners February 29, 2020 22:39
@vladar
Copy link
Contributor

vladar commented Mar 4, 2020

I don't have enough context but it sounds very similar to #17006 ? Or is it different? CC @wardpeet

@sbardian
Copy link
Contributor

sbardian commented Mar 5, 2020

@vladar @benedictjohannes I think #17006 does crop correctly, see the demo here. Could be wrong but seems correct to me and how I would use them. Queries for the crop examples can be seen here

@benedictjohannes
Copy link
Author

benedictjohannes commented May 4, 2020

@vladar @sbardian Yes, I've been checking #17006 and it basically solve what I'm trying to solve in a more holistic manner. As it's clearly the superior fix, I'm closing this PR. Thank you for pointing this out, I've tested the PR and it's working well (bootsrap based project). I can only hope that #17006 gets merged sooner, I'm really needing this functionality in my project.

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

Successfully merging this pull request may close these issues.

3 participants