Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Set the default mapping for jpeg->webp.#35

Closed
adamsilverstein wants to merge 40 commits into
add/new-webp-approach-brfrom
add/new-webp-approach-br-additional-changes
Closed

Set the default mapping for jpeg->webp.#35
adamsilverstein wants to merge 40 commits into
add/new-webp-approach-brfrom
add/new-webp-approach-br-additional-changes

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Aug 31, 2022

Copy link
Copy Markdown
Owner

eg. cat.jpeg, cat.jpg and cat.jpe (all valid jpegs) generate the same file names before this change, eg. cat-150x150.webp. adding the original file’s extension as a suffix on the generated filename neatly avoids this.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@adamsilverstein My main feedback here is what I mentioned earlier, I think it would be more efficient to handle the output format in a separate function hooked into the filter.

In addition to that, we should then also add tests to this PR:

  • For the new filter callback function.
  • For the re-introduced logic to ensure a unique file name (we can probably reuse a test from the reverted commit for that).

Comment thread src/wp-includes/class-wp-image-editor.php Outdated
@adamsilverstein

Copy link
Copy Markdown
Owner Author

Added a test for wp_default_image_output_mapping, the name change functionality is covered by changes to test_generate_filename

Comment thread tests/phpunit/tests/ajax/MediaEdit.php Outdated
*/
public function testImageEditOverwriteConstant() {
define( 'IMAGE_EDIT_OVERWRITE', true );
$files_that_shouldnt_exist = array();

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

this test was failing with $files_that_shouldnt_exist undefined below (https://github.com/adamsilverstein/wordpress-develop-fork/pull/35/files#diff-7e3d8ea591299762db2be94e68100b267611327378a1e94a8fbe0cc1666538adL106), I'm going to debug why a little further

@felixarntz felixarntz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@adamsilverstein A bit more feedback about the filter callback function, mostly minor stuff. We should have a bit more test coverage though.

Comment thread src/wp-admin/includes/media.php
Comment thread src/wp-admin/includes/media.php Outdated
Comment thread src/wp-admin/includes/media.php Outdated
Comment thread tests/phpunit/tests/image/editor.php
Comment thread tests/phpunit/tests/image/editor.php
Comment thread tests/phpunit/tests/media.php Outdated
Comment thread tests/phpunit/tests/rest-api/rest-attachments-controller.php Outdated
Comment thread tests/phpunit/tests/media.php
Comment thread tests/phpunit/tests/post/attachments.php Outdated
Comment thread tests/phpunit/tests/rest-api/rest-attachments-controller.php Outdated
@adamsilverstein

Copy link
Copy Markdown
Owner Author

I figured out why the testImageEditOverwriteConstant test was failing: a bug in wp_save_image - when the mime type was transformed during save, the meta incorrectly stored the un-transformed file name. this commit fixes it: a1af747 (#35). I removed the change from the test, should pass now.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@adamsilverstein Almost good to go now, except one tiny comment below, plus more tests like I mentioned in https://github.com/adamsilverstein/wordpress-develop-fork/pull/35/files#r962033794 still need to be added.

Comment thread src/wp-admin/includes/image-edit.php
Comment thread tests/phpunit/tests/image/editor.php
@adamsilverstein

Copy link
Copy Markdown
Owner Author

Updates:

  • Test that wp_default_image_output_mapping doesn't overwrite existing mappings
  • Test that the image editor default output for JPEGs is WebP
  • Add missing tear_down
  • cleanup

Tests pass locally, rerunning across envs in WordPress#3162

@felixarntz felixarntz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@adamsilverstein LGTM, except for a few comments on the one test.

Comment thread tests/phpunit/tests/media.php Outdated
Comment thread tests/phpunit/tests/media.php Outdated
Comment thread tests/phpunit/tests/media.php Outdated

if ( $editor->supports_mime_type( 'image/webp' ) ) {
$this->assertSame( 'image/webp', $saved['mime-type'] );
$this->assertSame( 'canola-100x75.webp', $saved['file'] );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't this result in canola-100x75-jpg.webp? Why is that extra original extension suffix missing here? Is that a potential problem we need to fix?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I looked into this a little. I think it is because of the way the test is structured with generate_filename called with no arguments. Our code in this function relies on $extension being passed, which is what happens when core generates subsized images. I'll see if we can improve this and also test the core calls to create the -scaled and -rotated names which may not be adding the additional suffix, but probably should.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Turns out this was happening because of the way the test was structured. By first generating the filename, then passing that to save the code was bypassing the for altered extension - that only happens when you don't pass a filename to save, see https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-image-editor-imagick.php#L717-L719

Fixed this in c0367e1 by altering the test slightly, calling save without first generating the filename. Essentially if you pass a filename to save, it uses that filename, that is a requirement for being able to overwrite files.

@adamsilverstein

Copy link
Copy Markdown
Owner Author

Once tests pass I'm going to commit so the feature lands before beta. we can address any edge case issues raised around file naming or add more tests during the beta.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@adamsilverstein Awesome work!

@adamsilverstein

Copy link
Copy Markdown
Owner Author

merged, closing

adamsilverstein pushed a commit that referenced this pull request Jul 31, 2025
Screencast have updated their URL structure to use a sub-domain and the prior oEmbed endpoint in the allow list now returns a `410 Gone` response.

For discussion regarding the legacy endpoint refer to [comment:35:ticket:61941 #61941, comment #35] onwards.

See #61941.
Props audrasjb, brhodes, dustintechsmith, joedolson, johnbillion, nikunj8866, paulstanos, peterwilsoncc, sandeepdahiya, sergeybiryukov, sirlouen, swissspidy.


git-svn-id: https://develop.svn.wordpress.org/trunk@60345 602fd350-edb4-49c9-b593-d223f7449a82
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.

2 participants