Skip to content

Multi-mime support, use WebP for content when smaller #2393

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

Closed

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Mar 8, 2022

Trac ticket: https://core.trac.wordpress.org/ticket/55443


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.

@adamsilverstein adamsilverstein force-pushed the add/webp-uploads branch 5 times, most recently from 2e6bd30 to 503a299 Compare March 10, 2022 00:36
adamsilverstein and others added 2 commits July 19, 2022 19:22
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
@adamsilverstein
Copy link
Member Author

adamsilverstein commented Jul 20, 2022

You might want to try to add some tests for wp_delete_attachment() to cover the new parts so that it does delete the files for the additional sources as expected

I see we do have it_should_remove_the_generated_webp_images_when_the_attachment_is_deleted (and a few other related tests) in tests/phpunit/tests/image/editor.php (and I see some since tags need updating in there). Easy to miss this file as GitHub has it collapsed by default! I will check if this can be expanded at all.

@adamsilverstein
Copy link
Member Author

regarding reading EXIF data, I found another instance we we have a filterable list of types which support reading EXIF data; I wonder if we should use the same list (plus WebP) here, looks like tiff image which we support also include EXIF data:

/**
* Filters the image types to check for exif data.
*
* @since 2.5.0
*
* @param int[] $image_types Array of image types to check for exif data. Each value
* is usually one of the `IMAGETYPE_*` constants.
*/
$exif_image_types = apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) );
if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types, true ) ) {

@adamsilverstein
Copy link
Member Author

@felixarntz in 253e908 I tried switching from set_mime_type to set_output_mime_type. Because we are only setting the output type now, the main image mime data remains the original type, so we no longer need to remove the exif check only for jpeg part. I'll do more testing to make sure this works as expected (so far, so good).

@felixarntz
Copy link
Member

@adamsilverstein Pushed one tiny code fix in ab79356.

Comment on lines 441 to 443
* @param string $dest_path
* @param string $extension
* @return string filename
Copy link
Member

Choose a reason for hiding this comment

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

@adamsilverstein Nitpick, but since we've now added documentation for $suffix, it may be good to document the other parameters and the return value 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.

Documented in feaea78 (#2393)

@adamsilverstein
Copy link
Member Author

Addressing final feedback and looking into failing test, the output_mime_type change is breaking the test_set_quality_with_image_conversion test and I'm digging into what the best fix is.

@adamsilverstein
Copy link
Member Author

Fix for the final test issue in ebe3ad4 (#2393)

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.

LGTM! From my perspective this is basically good to commit now 🎉

// Check if any of the new sizes already exist.
if ( isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) {
foreach ( $image_meta['sizes'] as $size_name => $size_meta ) {
if ( isset( $sizes ) && is_array( $sizes ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I may be missing something here, but thought I'd check in.
It looks like this is checking $sizes, which is set to array() just above and can only be empty.

Why is $image_meta['sizes'] no longer checked?

I haven't made it through the rest of the PR yet, so it's possible I'm missing context.
If this is no longer needed due to other flow changes, would it make sense to change things, since the variable is set to array() just above?

Copy link
Member Author

@adamsilverstein adamsilverstein Jul 21, 2022

Choose a reason for hiding this comment

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

Good catch! this was a bug probably from a late refactor that would only affect retries (when _wp_make_subsizes is used). I restored the previous behavior now - the only difference from trunk now is adding the mime type checks so each mime type can be checked.

Fixed in f1db696 (#2393)

I verified retries work by setting my PHP timeout very low and uploading a large image.

@adamsilverstein
Copy link
Member Author

closed in https://core.trac.wordpress.org/changeset/53751

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.

6 participants