Skip to content

Allow control for which image sizes to generate additional MIME type versions #415

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

eugene-manuilov
Copy link
Contributor

Summary

Fixes #413

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@eugene-manuilov eugene-manuilov added [Type] Enhancement A suggestion for improvement of an existing feature [Focus] Images [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) labels Jul 3, 2022
@eugene-manuilov eugene-manuilov added this to the 1.3.0 milestone Jul 3, 2022
Copy link
Contributor

@jjgrainger jjgrainger left a comment

Choose a reason for hiding this comment

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

@eugene-manuilov Looks good, just added a comment following on from @peterwilsoncc review

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.

@eugene-manuilov This mostly looks solid. I have some thoughts on the data format chosen here which is overly complicated IMO. It makes sense to be able to use isset over array_search, but we should not make such very "minor" performance enhancements at the cost of developer experience (the duplication of data there right now is problematic to me). We can probably find a way to do it in a way that is both performant and more clear for developers.

@felixarntz felixarntz changed the title Enhancement/413 allow control for which sizes to generate webp Allow control for which image sizes to generate additional MIME type versions Jul 6, 2022
);

foreach ( $additional_sizes as $size => $size_details ) {
if ( ! empty( $size_details['provide_additional_mime_types'] ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

where does provide_additional_mime_types property come from or this something you were thinking we would add later?

Copy link
Member

Choose a reason for hiding this comment

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

This would be the field that can later be populated via add_image_size's additional parameter. So having this here prepares us for that.
Technically, one could already set it now by directly touching the $_wp_additional_image_sizes global - which of course is discouraged, but I think it makes sense supporting this here already since we'll need it anyway and it's technically possible.

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.

@eugene-manuilov Production code looks good, however we should remove all the additional sizes again. The remaining feedback is exclusively some minor things about tests.

@felixarntz felixarntz requested a review from peterwilsoncc July 12, 2022 21:18
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.

@eugene-manuilov Looks great, thank you!

@felixarntz
Copy link
Member

@adamsilverstein @peterwilsoncc Can you please give this a pass too? We need at least a second approval :)

add_image_size( 'allowed_size_400x300', 400, 300, true );
add_image_size( 'not_allowed_size_200x150', 200, 150, true );

$GLOBALS['_wp_additional_image_sizes']['allowed_size_400x300']['provide_additional_mime_types'] = true;
Copy link
Member

Choose a reason for hiding this comment

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

I assume this could be removed once we update add_image_size to accept the new "output_additional_mimes" parameter, right? Can you add a TODO comment to remove this once that is in place?

@adamsilverstein
Copy link
Member

+1 looks good to me, I left one request to comment on the $GLOBAL setting line in the tests which shouldn't be needed once add_image_size is updated.

@felixarntz
Copy link
Member

@adamsilverstein Added the TODO comment, back to you for approval.

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

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

Excellent!

@felixarntz felixarntz merged commit 0014eac into trunk Jul 12, 2022
@felixarntz felixarntz deleted the enhancement/413-allow-control-for-which-sizes-to-generate-webp branch July 12, 2022 23:11
@felixarntz
Copy link
Member

FYI: WordPress/wordpress-develop#3166 is the new PR that implements a slightly modified version of this for WordPress core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow control for which sizes to generate a WebP version
6 participants