-
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
Update the_content
with the appropiate image format
#152
Conversation
Uses `image/webp` if supported by the client and updates the `image/jpeg`, `image/jpg` formats with the modern format if avaiable. References in the content are updated with the WebP format if available. Fixes #149
…e/149-update-the-content
…into feature/149-update-the-content
…into feature/149-update-the-content
…into feature/149-update-the-content
…into feature/149-update-the-content
Update the content from the sites using WebP images when available instead of JPEG or JPG images.
…into feature/149-update-the-content
The assertion would make sure both are not the same, meaning at least one has a different markup.
…into feature/149-update-the-content
This worked well in my testing across a variety of themes. The only issue I noticed was when inserting an image at the "large" size with a large image upload that results in a |
Thanks for taking the time to test it, currently this is expected and described here: performance/modules/images/webp-uploads/load.php Lines 414 to 417 in 7b38de8
Based on the decision from: The code would be updated accordingly if required. |
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
…/performance into feature/149-update-the-content
I noticed that as well, it depends on the viewport size and pixel density. Since we currently don't have WebP versions for the "full" size (whether The problem is that most modern screens have a high pixel density like If you want to test this more specifically without the above caveats, you can put a temporary filter in place to ensure WordPress never chooses a size greater than the image size you actually specified (which may cause blurry images on larger or high-density devices though): add_filter(
'wp_calculate_image_srcset',
function( $sources, $size_array ) {
foreach ( $sources as $index => $source ) {
if ( 'w' === $source['descriptor'] && $source['value'] > $size_array[0] ) {
unset( $sources[ $index ] );
}
}
return $sources;
},
10,
2
); There's certainly room for optimization in core's default behavior there, but that's a separate rabbit hole :)
I agree this gives us an answer for #174, that we should also generate a WebP version of the |
Move logic to replace image references into a separate function, update tests accordingly as well.
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.
@mitogh Great! I left a few follow-up comments, mostly minor though. This is almost ready.
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Adding `$context` parameter to match what core uses inside of `wp_filter_content_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.
This one open discussion is the only thing we need to finalize before we can merge this.
Update mechanism to use WP core mechanism to parse image tags inside of the content of the post.
Thanks, @felixarntz just updated to code to follow what WP Core uses in order to reduce the friction in the scenario this would be merged into WP Core. Let me know in case you have any additional feedback. |
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.
Awesome work @mitogh!
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.
Code looks great to me, thanks for the structural changes that will make prepping this for core more straightforward. Also retested and everything worked well in my testing.
Summary
Uses
image/webp
if supported by the client and updates theimage/jpeg
,image/jpg
formats with the modern format if available.References in the content are updated with the WebP format if available.
Fixes:
the_content
with the correct image format #149Related with:
sources
for storage. #147Relevant technical choices
Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.