fix cover sizing for videos with aspect ratios < 1 #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was using vidim for a video background with a vertical aspect ratio (3/4) and found that the video wasn't consistently covering the space like the horizontal ratios would.
I have not been able to build the project for testing, but I think the fix is pretty simple. This "just worked" for my project, but for my own sanity I'm going to walk through what happens with the current code on vertical videos.
This is the current code:
Which means that a video with an aspect ratio of
0.75
will fit to the height of its container when( containerHeight / containerWidth ) < 0.75
, and otherwise fit to its width.This makes the breakpoint for the container a
4/3
aspect ratio. So when the container is wider than4/3
, the3/4
video will fit to its height, showing the full video but leaving empty space on either side. When the container is narrower than4/3
, the3/4
video will fit to its width, filling the container until the container gets narrower than the background video's3/4
aspect ratio. At this point empty space will begin to appear above and below the video.Simplifying the above to use the same rules for vertical and horizontal ratios...
...keeps the container breakpoint the same as the video ratio, and means that it will always fit to height when the container is taller than the video, and fit to width when the container is wider than the video.
Fwiw I only tested this on a self-hosted video, not Youtube, so I don't know if vertical youtube videos have some other behavior that the current code is accounting for.