-
-
Notifications
You must be signed in to change notification settings - Fork 22
feat: Add width and height attributes on non-responsive images #97
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
feat: Add width and height attributes on non-responsive images #97
Conversation
For images with a single source, add the width and height attributes to the img tag in order to help browsers compute the page layout more quickly. If the width and height attributes were already present on the img tag, they are left untouched.
justinmayer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems sensible to me. Any thoughts, @minchinweb?
|
Edit: Oops, comment got added to the wrong issue! |
| process_image((path.source, destination, process), settings) | ||
| image_size = process_image((path.source, destination, process), settings) | ||
| if image_size: | ||
| if "width" not in img.attrs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adding a width attribute to the HTML <img> tag, right? (i.e. nothing to do with the Exif tags)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Here, img is the HTML image tag parsed from the HTML generated from the user content.
|
Look good to me! I had to look at this on my computer to make sense of it, but I was mostly over-complicating things. I added a doc string for the function, so it that looks good on your side, please merge. @justinmayer Will you merge this one? Also, with these two, it's probably time to cut a release; are you up for that? |
|
Yes, I will issue a release tomorrow. Many thanks to @patrickfournier for the enhancement and to @minchinweb for the review and doc-string addition. Much appreciated! 💫 |
|
Release issued 🎉 https://github.com/pelican-plugins/image-process/releases/tag/3.2.0 |
This pull request enhances the
image_processplugin by updating image processing logic for non-responsive images to automatically addwidthandheightattributes to<img>tags based on the processed image actual dimensions. The tests have been updated to reflect this new behavior, ensuring that images without pre-existing size attributes receive them, while existing attributes remain unchanged.Having
widthandheightattributes helps the browsers to compute the page layout more quickly, since it does not have to wait for the images to be loaded to know their size.Image processing logic improvements:
process_imagefunction now returns the processed image's width and height, andprocess_img_taguses these values to setwidthandheightattributes on<img>tags if they are not already present.Test suite updates:
test_image_process.pyhave been updated to expectwidthandheightattributes in processed<img>tags, and mocks forprocess_imagenow return fake image dimensions.test_path_normalizationnow use BeautifulSoup to parse and assert on individual tag attributes, making them more robust to attribute order and formatting.