-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Adjust WebP generation for only certain JPEG sizes #3166
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
Conversation
adamsilverstein
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.
Overall this looks really good, left some doc block alignment suggestions. I'm going to review and test this locally as well
…e JPEG to WebP mapping per image size.
|
@adamsilverstein In 7df09fd, I've added the relevant logic to control WebP output per size, which we can later iterate on further based on the Left to do here is expanding test coverage to account for the new logic there. |
…al for filter callback for clarity.
|
This should be ready for a comprehensive review (and hopefully commit) now. |
| if ( $is_image ) { | ||
| /** This filter is documented in wp-includes/class-wp-image-editor.php */ | ||
| $output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type ); | ||
| $output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type, '' ); |
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.
We should call out in the dev note that there is no size when core calls wp_unique_filename because this is applied only to the upload image (not the sub-sizes). might be confusing that it is called this way.
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.
@adamsilverstein Good point, the additional parameter for this definitely needs to be explained in the dev note. FWIW, it's not only in wp_unique_filename that this is empty, it's always empty when no particular image size is being handled. For example even within WP_Image_Editor usage, the parameter will be an empty string for the original image, or the full image, or any custom operation (e.g. cropping the site icon). Only interactions that relate to a specific registered image size will result in the parameter being not empty.
adamsilverstein
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.
Excellent work!
|
Committed in https://core.trac.wordpress.org/changeset/54097. |
This is a work in progress to bring awareness of the image size name to
WP_Image_Editor, and then pass the value to theimage_editor_output_formatfilter, so that filter callbacks can make a contextual decision based on the image size. This will then be used to specify the output format forimage/jpegto be conditionallyimage/webp, depending on whether this is configured for the given image size.Trac ticket: https://core.trac.wordpress.org/ticket/56526
Relevant decisions
WP_Image_Editorhas been implemented in a fully backward compatible way which also works with any custom sub class implementations.$sizeproperty.wp_default_image_output_mapping()filter callback to now set theimage/jpegtoimage/webpmapping only if the given size supports it.wp_default_image_output_mapping()function is included.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.