-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Unit tests that confirm that the original image is properly converted to additional mime type #7733
Unit tests that confirm that the original image is properly converted to additional mime type #7733
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The [59317] changes make some changes in attachment metadata. In 6.7 branch
In current trunk
Check the |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
tests/phpunit/tests/media.php
Outdated
$webp_sizes = wp_generate_attachment_metadata( $attachment_id, $file ); | ||
remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_webp' ) ); | ||
|
||
$this->assertSame( $file, $webp_sizes['file'], 'The original file name should same.' ); |
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.
I think this should be original_image
, as file
is intended to be the full size version of the converted image.
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.
I agree, this comparison doesn't look right.
That said, I'm unclear what this test is covering. Per https://core.trac.wordpress.org/ticket/62305#comment:34, the Core change itself is not a bug. It does change the attachment metadata, but that's because of what it fixes (consistently convert the image if it requires conversion, regardless of whether it needs to also be scaled down or not).
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.
I think this should be original_image, as file is intended to be the full size version of the converted image.
..
It does change the attachment metadata, but that's because of what it fixes
Right. This is the actual bugfix from https://core.trac.wordpress.org/ticket/62305. Before https://core.trac.wordpress.org/changeset/59317 the uploaded image (i.e. the file
from the image meta array) was not converted when conversion was required. After the fix it is converted.
This bug has existed for a while but became more visible/severe when converting .heic images as the originally uploaded image cannot be used in most browsers but WordPress was using it anyway.
Thinking this test can perhaps be changed to confirm that the original image is converted (when smaller than the big image threshold).
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.
Got it. Thanks for clarification 🙌
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.
My question is why the full size image generated with 33772-1920x1080.webp
not 33772.webp
? It's just observation not a concern. We should return 33772.webp
for full size image.
When i upload https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/data/images/33772.jpg image it generates below images:
- 33772-150x150.jpg
- 33772-300x169.jpg
- 33772-768x432.jpg
- 33772-1024x576.jpg
- 33772-1536x864.jpg
- 33772.jpg
But when i convert JPEG to WEBP it generates below images:
- 33772-150x150.webp
- 33772-300x169.webp
- 33772-768x432.webp
- 33772-1024x576.webp
- 33772-1536x864.webp
- 33772-1920x1080.webp
- 33772.jpg
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.
@peterwilsoncc Something like -converted
would be okay for me, though I would prefer to consider changing that internal logic - as in: If the file extension is different from the input image, it should be possible to keep using the same name (except the extension of course).
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.
I agree changing the logic would be optimal but I think other falsey values can end up being used, eg ::get_suffix()
can return false
. So ::generate_filename( ::get_suffix() )
requires the loose check (I briefly considered using false
to indicate no suffix)
Using -converted
is the smaller fix but WP would be stuck with it forever more, so I'm tempted to put in the snowflake code for now to allow for any niceties later. Either way I am happier than using the dimensions.
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.
Yes, for a moment I was considering to change ::generate_filename()
to accept an empty string for no suffix. Didn't because of RC, but will open a ticket for 6.8.
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.
Hm, another option here may be to include the old file extension as a suffix? For example: converting image.heic
to JPEG would produce image-heic.jpg
?
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.
Hm, another option here may be to include the old file extension as a suffix? For example: converting
image.heic
to JPEG would produceimage-heic.jpg
?
This is what we did in Modern Image Formats.
I've incorproated these tests in to #7748 with a few modifications to use HEIC testing to allow it to rely on the default core features. |
|
@peterwilsoncc In 76a5c39 i incorporate changes from PR #7748 but now it return original image instead WebP mime type.
|
@mukeshpanchal27 That looks like it was due to the regex error @felixarntz picked up in #7748 (comment) |
@peterwilsoncc Do we need these PR or can we close it? |
@mukeshpanchal27 This was included in the follow up PR. |
Track ticket: https://core.trac.wordpress.org/ticket/62305