WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/20/2021 10:14:47 PM (7 months ago)
Author:
antpb
Message:

Media: Introduces image_editor_output_format filter for setting default MIME type of sub size image output.

This change introduces the image_editor_output_format filter, which fires as sub size images are generated allowing to define a default image MIME type for those items.

Props adamsilverstein, williampatton, spacedmonkey, mikeschroder, hellofromTonya, justinahinon, Boniu91, antpb, SergeyBiryukov.
Fixes #52867.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/intermediateSize.php

    r49024 r50943  
    6464
    6565    /**
     66     * @requires function imagejpeg
     67     * @ticket 52867
     68     */
     69    function test_image_editor_output_format_filter() {
     70        add_filter(
     71            'image_editor_output_format',
     72            function() {
     73                return array( 'image/jpeg' => 'image/webp' );
     74            }
     75        );
     76        $file   = DIR_TESTDATA . '/images/waffles.jpg';
     77        $image  = image_make_intermediate_size( $file, 100, 75, true );
     78        $editor = wp_get_image_editor( $file );
     79        if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
     80            $this->assertSame( 'image/jpeg', $image['mime-type'] );
     81        } else {
     82            $this->assertSame( 'image/webp', $image['mime-type'] );
     83        }
     84        unlink( DIR_TESTDATA . '/images/' . $image['file'] );
     85        remove_all_filters( 'image_editor_output_format' );
     86    }
     87
     88    /**
    6689     * @ticket 17626
    6790     * @requires function imagejpeg
Note: See TracChangeset for help on using the changeset viewer.