Skip to content

Ensure the -scaled image remains in the original uploaded format #143

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

Merged
merged 8 commits into from
Feb 7, 2022

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Feb 1, 2022

Summary

When uploading very large images (over the big_image_size_threshold filter threshold), WordPress creates a scaled version of the image with the word-scaled appended to the file name. It stores a reference to the original image in the image meta original_image field, see this make post for more details.

WordPress subsequently uses the "scaled" image as if it were the original in most use cases (only going back to the true original image when editing the image). This causes the mime type shown in the media library for a large jpeg upload to show as image/webp because the scaled image is a WebP.

To fix that, in this PR I skip the -scaled image, leaving it in the original format of the uploaded image.

This matches the behavior of uploading a smaller image that isn't over the big_image_size_threshold, improving consistency.

Fixes #67

Relevant technical choices

  • Makes sense that the scaled image, which WordPress largely treats as the "original" would remain in the mime type of the upload
  • Ensure the behavior is consistent between large and smaller image uploads.

Checklist

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

@adamsilverstein adamsilverstein added [Focus] Images [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken labels Feb 1, 2022
@adamsilverstein adamsilverstein added this to the 1.0.0-beta.1 milestone Feb 1, 2022
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.

Looks good, just two comments.

@mitogh
Copy link
Member

mitogh commented Feb 2, 2022

Additionally if we are going with this route once this is merged we should be able to close:

adamsilverstein and others added 2 commits February 2, 2022 14:13
Co-authored-by: Crisoforo Gaspar Hernández <hello@crisoforo.com>
@adamsilverstein
Copy link
Member Author

Additionally if we are going with this route once this is merged we should be able to close:

Thinking we should generate both, see #142 (comment)

@adamsilverstein adamsilverstein force-pushed the fix/skip-scaled-transform branch from c0eba71 to 98e1003 Compare February 2, 2022 22:43
@adamsilverstein adamsilverstein force-pushed the fix/skip-scaled-transform branch from 98e1003 to b223e89 Compare February 2, 2022 22:44
@adamsilverstein adamsilverstein force-pushed the fix/skip-scaled-transform branch from 4e551c8 to 7a2bbe4 Compare February 2, 2022 22:52
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] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image mime type is not set correctly when a webp image is generated.
3 participants