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

Try setting aspect-ratio on images lacking width and height #1420

Closed

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jul 31, 2024

Summary

I started looking at this because I was checking how well Image Prioritizer optimizes a Timber-based theme. It adds fetchpriority=high and lazy-loading correctly, but the Timber starter theme does not include width and height attributes on the featured image, and Image Prioritizer hasn't yet implemented this either. So I wanted to see what it would take.

This experiment tries to set an aspect-ratio on img tags that are missing width and height attributes. There is currently a big problem, however, in that it is setting the aspect-ratio based on the clientBoundingRect and not the intrinsic dimensions of the image. This means that once the aspect-ratio is set the next time that detect.js measures the image, it will use the aspect-ratio for subsequent measurements, meaning that the image dimensions will become locked in place. In order to get around this, I think detect.js may need to be extend to obtain the intrinsic dimensions of elements that have them: img, video, canvas, svg (maybe), and input[type=image] (ewwww).

Another problem is that in order to set the aspect-ratio, the element has to also have width:100% added. This may not be what is intended!

Fixes #10

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) labels Jul 31, 2024
@westonruter
Copy link
Member Author

Closing since the aspect-ratio approach is not viable. Better to set the width and height attributes on the element to be the corresponding intrinsic dimensions.

@swissspidy swissspidy deleted the try/set-aspect-ratio-on-dimensionless-images branch October 11, 2024 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Image Prioritizer Issues for the Image Prioritizer plugin (dependent on Optimization Detective) [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Done 😃
Development

Successfully merging this pull request may close these issues.

Visual tool to scan a page and report missing width/height elements
1 participant