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

Add WebP. #1137

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft

Conversation

adamsilverstein
Copy link
Member

Trac ticket:


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Contributor

@desrosj desrosj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few questions I had reading through the code!

*
* @param int $quality Quality level between 0 (low) and 100 (high) of the WebP.
*/
return imagewebp( $image, null, apply_filters( 'webp_quality', 75 ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why the quality is 75 here, but 90 above. Also, is there any quality comparison data to show that this is a good number? When the quality level for JPEGs was adjusted in 4.5, there as some pretty extensive research that we were able to point to justifying the number that was chosen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing!

We discussed this a bit previously - 90 is for transforms, 75 for saves - see this and following comment - https://core.trac.wordpress.org/ticket/35725#comment:137

More research is probably warranted to further fine tune the default WebP quality (and can continue after the initial commit).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems a bit odd to me. If we are using different quality values here, why don't we do the same for JPEG? I agree more research here would be worth doing.

One other point of feedback that's more code-related: The jpeg_quality filter also passes additional context of edit_image. I'm thinking we should probably architect the new webp_quality filter in the same way and pass edit_image here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the 'edit_image' context. Odd that is the context because this is actually the 'save_image' function, but we can keep that way to match jpeg.

As for the quality, although it is shown as 90 here for jpeg, the quality for saves is actually set to 82 here ->

protected $default_quality = 82;

I will double check that the quality settings are used as I expect for jpeg and WebP.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these sections are legacy code and only apply when the passed image isn't an instance of WP_Image_Editor. I'm actually not sure that can happen, in my testing the image is always a WP_Image_Editor and the quality used is the default: 82. @getsource - any idea how an image could get passed that isn't an instance of WP_Image_Editor? If this is purely legacy code, we could remove the WebP support parts.

If we want to use a different value for WebP quality we could add this via the wp_editor_set_quality filter which passed the mime type as context. For now, feels fine to leave at the default value since we haven't studied the best level to use yet.

src/wp-admin/includes/image.php Show resolved Hide resolved
adamsilverstein and others added 9 commits April 20, 2021 09:53
Co-authored-by: Tonya Mork <hello@hellofromtonya.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality-wise mostly looks good, most feedback is about missing/incorrect documentation and some other code formatting problems.

Also there are some other violations flagged by WPCS which need to be fixed.

*
* @param int $quality Quality level between 0 (low) and 100 (high) of the WebP.
*/
return imagewebp( $image, null, apply_filters( 'webp_quality', 75 ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems a bit odd to me. If we are using different quality values here, why don't we do the same for JPEG? I agree more research here would be worth doing.

One other point of feedback that's more code-related: The jpeg_quality filter also passes additional context of edit_image. I'm thinking we should probably architect the new webp_quality filter in the same way and pass edit_image here as well.

src/wp-admin/includes/image-edit.php Outdated Show resolved Hide resolved
src/wp-includes/functions.php Outdated Show resolved Hide resolved
src/wp-includes/media.php Outdated Show resolved Hide resolved
src/wp-includes/media.php Show resolved Hide resolved
src/wp-includes/media.php Show resolved Hide resolved
src/wp-includes/media.php Outdated Show resolved Hide resolved
src/wp-includes/media.php Outdated Show resolved Hide resolved
src/wp-includes/media.php Show resolved Hide resolved
tests/phpunit/tests/functions.php Outdated Show resolved Hide resolved
adamsilverstein and others added 2 commits April 28, 2021 23:10
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
@adamsilverstein
Copy link
Member Author

@felixarntz thanks for the review and feedback.

This also seems a bit odd to me. If we are using different quality values here, why don't we do the same for JPEG? I agree more research here would be worth doing.

We do use different quality settings for JPEG as well (for saving vs. edits) so not sure what you are referring to. l will double check, but this should match the jpeg behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants