-
Notifications
You must be signed in to change notification settings - Fork 29
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
WidthCalculator needs some improvements when outputting small images #167
Comments
Good idea, I'd be happy if it was a bit smarter, right now it's mostly based on a guesstimate of file size and if it's worth it to create a new image for the resulting file size. I guess we could add some "fixed" widths in there based on the original source or the requested max size ( |
I have been thinking about this for some time. I think I want to approach this in a way where For example, I have had instances where I want fixed height for my responsive images, but unfortunately this addon does not handle height constraints at all, this addon follows the ratio instead. I have had a few places where page header is fixed height in a design, and having images generated with ratio was not efficient. Having ability to do whatever dimensions calculations I want would have helped here. We could ship with some Do they want super aggressive width calculator that covers all kinds of widths with an image every 20 pixels? Use What do you think of this? |
Dear contributor, because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it. |
You can now fix this by binding your own dimension calculator introduced in v3 that would workaround this issue.You can read about it more in the changelog and in the #193 PR. |
There are two issues:
First, WidthCalculator curently uses
glide:width
value only to filter out widths that are larger than the specified value. But the initial widths that have been calculated have been based on the asset dimensions, which is not particularly good if the asset is in high resolution, while we need a really small resolution on front-end.For example, I have 42x42px thumbnails for my gallery on mobile viewport, so I specify glide:width to be 126, and I expect decent width coverage for DPR of 1, 2 and 3 (42px, 84px and respectively 126px), but instead I only get 126px breakpoint because that is what is forced as only value, if no widths get calculated by WidthCalculator. A device with DPR of 1 should only need image with width 42px, but in this case it will request the only available image with 126px width. The steps multiplier 0.7 is using original asset dimensions for file size prediction, as such we end up with too large gaps between calculated widths.
The second matter is that because these gaps are too huge, you may end up where the browser determines that the blurry placeholder is the one that it will use. In my situation, if I do not cap the maximum width with
glide:width
, I get 32w placeholder and the next closest width is 672w. Because the picture container is 42px width, browser will pick the closest width, and I end up with blurry placeholders. While I can workaround this issue myself (either setting max width or outright disabling placeholders), novice users might find this confusing.As such, some adjustments have to be made to WidthCalculator class.
The text was updated successfully, but these errors were encountered: