Make WordPress Core

Opened 2 years ago

Last modified 18 months ago

#56288 accepted enhancement

Add mime output control to `add_image_size`

Reported by: adamsilverstein's profile adamsilverstein Owned by: adamsilverstein's profile adamsilverstein
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by sabernhardt)

Summary

  • Add an option to the add_image_size function so that developers can control whether secondary mime types are generated for the image size they are adding.

Description

In #55443 we introduced multi-mime support and the capability to generate sub-sizes in secondary mime types (or even to replace the primary output mime). The code includes a filter that enables developer control over which sizes output secondary mimes. This ticket aims to extend that work by adding control over secondary mime generation per size at the point of registration.

Considerations

This proposal is to add a new $output_mimes boolean parameter to the add_image_size function. I also considered instead adding an $output_options (keyed) array parameter, this would then have an option for output_mimes and in the future we could use this to enable a quality setting per size which we have discussed elsewhere already.

I decided to keep this PR simple by using a boolean vs an array because that is all we need now. I would appreciate feedback on this approach in addition to the code here or on the PR.

Attachments (6)

56288.diff (15.2 KB) - added by adamsilverstein 2 years ago.
56288.2.diff (9.1 KB) - added by adamsilverstein 2 years ago.
update from PR
56288.3.diff (16.7 KB) - added by adamsilverstein 2 years ago.
56288.4.diff (16.9 KB) - added by adamsilverstein 2 years ago.
56288.5.diff (16.9 KB) - added by adamsilverstein 2 years ago.
56288.6.diff (9.7 KB) - added by adamsilverstein 2 years ago.

Download all attachments as: .zip

Change History (28)

#1 @adamsilverstein
2 years ago

  • Description modified (diff)
  • Keywords has-patch added; needs-patch removed

#2 @adamsilverstein
2 years ago

  • Description modified (diff)

This ticket was mentioned in PR #3028 on WordPress/wordpress-develop by adamsilverstein.


2 years ago
#3

  • Keywords has-unit-tests added

#4 @sabernhardt
2 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


2 years ago

This ticket was mentioned in Slack in #core-media by adamsilverstein. View the logs.


2 years ago

adamsilverstein commented on PR #3028:


2 years ago
#7

@felixarntz Addressed your feedback here & ready for another review whenever you have a chance

@adamsilverstein
2 years ago

update from PR

#8 @adamsilverstein
2 years ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

adamsilverstein commented on PR #3028:


2 years ago
#9

@felixarntz updated based on your feedback, ready for another review

#10 @adamsilverstein
2 years ago

56288.3.diff includes the latest updates from the PR

#11 @adamsilverstein
2 years ago

  • Keywords needs-dev-note commit added; dev-feedback removed

56288.4.diff includes the final changes from the PR

#12 @adamsilverstein
2 years ago

56288.5.diff update against trunk

adamsilverstein commented on PR #3028:


2 years ago
#13

Also: Do we want to trigger a _doing_it_wrong() if the parameter is not passed? Or should we hold off until later? Note that if we don't trigger a warning here now, it may delay the point in time when we can change the default.

Reconsidering this: the additional error logging might be excessive for anyone who has error logging enabled - any existing image sizes need to get updated or they will throw a warning... I feel we should give developers one release cycle (at least) before adding this notice. what do you think?

So my idea would be to add this in 6.1 with a Dev Note, but no warning. The in 6.2 we can add the doing_it_wrong notice; finally, in 6.3 we will switch the default from null to true.

adamsilverstein commented on PR #3028:


2 years ago
#14

I removed the doing_it_wrong warning for now in `12986a3` (#3028) and will mention that on the Trac ticket as well.

This ticket was mentioned in Slack in #core-media by adamsilverstein. View the logs.


2 years ago

#17 @flixos90
2 years ago

In 54097:

Media: Generate WebP only for certain registered image sizes.

The existing filter image_editor_output_format receives an additional parameter $size_name which is populated whenever it controls the output format for a specific registered image size to create. Otherwise, it remains empty. In order to achieve this, a low level change has been added in bringing a new $size_name class property to the WP_Image_Editor base class, which is introduced in a backward compatible way that will not cause conflicts with custom implementations.

This parameter is then used in new logic inside the wp_default_image_output_mapping() callback function for the filter, controlling whether image/jpeg should map to image/webp output or not. By default, this is enabled for all WordPress core image sizes by default, and this list can be modified using a new wp_image_sizes_with_additional_mime_type_support filter, e.g. to remove core sizes or add custom sizes.

The customization per image size may be further enhanced by providing a more declarative API via a new parameter on the add_image_size() function.

Props eugenemanuilov, flixos90, adamsilverstein, joegrainger.

Fixes #56526.
See #55443, #56288.

felixarntz commented on PR #3028:


2 years ago
#18

@adamsilverstein Now that https://core.trac.wordpress.org/changeset/54097 has been committed, I suggest we refresh this PR against latest trunk and then adjust.

Most of the code here is still relevant as is, we just need to change the integration point which now is no longer in _wp_filter_image_sizes_additional_mime_type_support() but in wp_default_image_output_mapping().

#19 @desrosj
2 years ago

In 54210:

Coding Standards: Various alignment fixes from composer format.

Follow up to [53874], [54097], [54110], [54155], [54162], [54184].

See #39210, #55443, #56288, #56092, #56408, #56467, #55881.

#20 @davidbaumwald
2 years ago

  • Keywords needs-dev-note commit removed
  • Milestone changed from 6.1 to Future Release

After reverting WebP in core for 6.1(r54226), @adamsilverstein and @flixos90 confirmed that this should move to Future Release for continued work.

#21 @adamsilverstein
2 years ago

  • Status changed from assigned to accepted

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


18 months ago

Note: See TracTickets for help on using tickets.