-
Notifications
You must be signed in to change notification settings - Fork 101
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
Account for responsive images being disabled when generating a PICTURE element #1449
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Nice catch! Just some small nitpicks here related to my comment on the original issue.
After 7e09a72, The picture element outputs: Responsive image:<picture class="wp-picture-12" style="display: contents;">
<source type="image/webp"
srcset="
http://localhost:8888/wp-content/uploads/2024/08/car-300x169-jpeg.webp 300w,
http://localhost:8888/wp-content/uploads/2024/08/car-1024x576-jpeg.webp 1024w,
http://localhost:8888/wp-content/uploads/2024/08/car-768x432-jpeg.webp 768w
"
sizes="(max-width: 1080px) 100vw, 1080px"
>
<img
fetchpriority="high"
decoding="async"
width="1080"
height="608"
src="http://localhost:8888/wp-content/uploads/2024/08/car.jpeg"
alt=""
class="wp-image-12"
srcset="
http://localhost:8888/wp-content/uploads/2024/08/car.jpeg 1080w,
http://localhost:8888/wp-content/uploads/2024/08/car-300x169.jpeg 300w,
http://localhost:8888/wp-content/uploads/2024/08/car-1024x576.jpeg 1024w,
http://localhost:8888/wp-content/uploads/2024/08/car-768x432.jpeg 768w
"
sizes="(max-width: 1080px) 100vw, 1080px"
>
</picture> No responsive image (use
|
picture
and source
tags when the responsive image disabledIMG >src
when the responsive image disabled
IMG >src
when the responsive image disabledIMG>src
when the responsive image disabled
… fix/follow-up-1399
@westonruter Thanks for the feedback. After the new helper function the result of single and multi-mime type images are: Multi Mime
Medium Size<picture class="wp-picture-43" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-300x169-jpeg.avif"
>
<source
type="image/webp"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-300x169-jpeg.webp"
>
<img
fetchpriority="high"
decoding="async"
width="300"
height="169"
src="http://localhost:8888/wp-content/uploads/2024/08/car-300x169.jpeg"
alt=""
class="wp-image-43"
>
</picture> Large Size<picture class="wp-picture-43" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-1024x576-jpeg.avif"
>
<source
type="image/webp"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-1024x576-jpeg.webp"
>
<img
decoding="async"
width="1024"
height="576"
src="http://localhost:8888/wp-content/uploads/2024/08/car-1024x576.jpeg"
alt=""
class="wp-image-43"
>
</picture> Full Size<picture class="wp-picture-43" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-jpeg.avif"
>
<source
type="image/webp"
srcset="http://localhost:8888/wp-content/uploads/2024/08/car-jpeg.webp"
>
<img
decoding="async"
width="1080"
height="608"
src="http://localhost:8888/wp-content/uploads/2024/08/car.jpeg"
alt=""
class="wp-image-43"
>
</picture> Single Mime
Medium Size<picture class="wp-picture-46" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/leaves-300x200-jpg.avif"
>
<img
loading="lazy"
decoding="async"
width="300"
height="200"
src="http://localhost:8888/wp-content/uploads/2024/08/leaves-300x200.jpg"
alt=""
class="wp-image-46"
>
</picture> Large Size<picture class="wp-picture-46" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/leaves-1024x683-jpg.avif"
>
<img
loading="lazy"
decoding="async"
width="1024"
height="683"
src="http://localhost:8888/wp-content/uploads/2024/08/leaves-1024x683.jpg"
alt=""
class="wp-image-46"
>
</picture> Full Size<picture class="wp-picture-46" style="display: contents;">
<source
type="image/avif"
srcset="http://localhost:8888/wp-content/uploads/2024/08/leaves-jpg.avif"
>
<img
loading="lazy"
decoding="async"
width="1080"
height="720"
src="http://localhost:8888/wp-content/uploads/2024/08/leaves.jpg"
alt=""
class="wp-image-46"
>
</picture> |
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.
Curious: in #1449 (comment) you show examples of how this works when different image sizes are requested, but how is the size being selected for the alternative mime types? I don't see how the size selection works.
plugins/webp-uploads/helper.php
Outdated
if ( isset( $metadata['sizes'] ) && is_array( $metadata['sizes'] ) ) { | ||
foreach ( $metadata['sizes'] as $size => $size_data ) { | ||
|
||
if ( empty( $size_data['file'] ) ) { |
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.
Can we avoid using empty() here?
Co-authored-by: Weston Ruter <westonruter@google.com>
@westonruter When we disabled the responsive images then it will return only |
I'm not actively familiar enough with the internals of image handling in WP without taking time to dive in deeper. I'll defer to @joemcgill and @adamsilverstein who have more experience to finish the reviews. |
Punting from the 3.4.0 release since we're out of time. If this does get reviewed by Monday morning, make sure the PR's base branch is updated from |
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.
Nice fix!
IMO too big of a change to merge now 1 hour before release. I'd say let's get this into the next one. |
Agreed. Merging into trunk and not into the release branch. |
IMG>src
when the responsive image disabled
@mukeshpanchal27 I updated the PR title to be more clear. Please review and amend further as needed. |
Summary
Fixes #1448
After the PR: