Media: enable control of progressive image output.

Add a new `image_save_progressive` filter which developers can use to control whether intermediate image sizes are saved in a progressive format (when available). By default, progressive image output is not used, matching the previous behavior.

Props: adamsilverstein, _ck_, markoheijnen, SergeyBiryukov, Japh, pmeenan, mikeschroder, derekspringer, buley, ericlewis, bahia0019, born2webdesign.
Fixes #21668.


Built from https://develop.svn.wordpress.org/trunk@57607


git-svn-id: http://core.svn.wordpress.org/trunk@57108 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Adam Silverstein 2024-02-12 23:26:11 +00:00
parent 8d04dc7e1c
commit a843b188f8
3 changed files with 26 additions and 5 deletions

View File

@ -504,6 +504,11 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
$filename = $this->generate_filename( null, null, $extension ); $filename = $this->generate_filename( null, null, $extension );
} }
if ( function_exists( 'imageinterlace' ) ) {
/** This filter is documented in wp-includes/class-wp-image-editor-imagick.php */
imageinterlace( $image, apply_filters( 'image_save_progressive', false, $mime_type ) );
}
if ( 'image/gif' === $mime_type ) { if ( 'image/gif' === $mime_type ) {
if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) { if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) {
return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );

View File

@ -489,10 +489,6 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
$this->image->setImageDepth( 8 ); $this->image->setImageDepth( 8 );
} }
} }
if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) {
$this->image->setInterlaceScheme( Imagick::INTERLACE_NO );
}
} catch ( Exception $e ) { } catch ( Exception $e ) {
return new WP_Error( 'image_resize_error', $e->getMessage() ); return new WP_Error( 'image_resize_error', $e->getMessage() );
} }
@ -825,6 +821,23 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
} }
if ( method_exists( $this->image, 'setInterlaceScheme' ) && method_exists( $this->image, 'getInterlaceScheme' ) && defined( 'Imagick::INTERLACE_PLANE' ) ) {
$orig_interlace = $this->image->getInterlaceScheme();
/**
* Filters whether to output progressive images (if available).
*
* @since 6.5.0
*
* @param bool $interlace Whether to use progressive images for output if available. Default false.
* @param string $mime_type The mime type being saved.
*/
if ( apply_filters( 'image_save_progressive', false, $mime_type ) ) {
$this->image->setInterlaceScheme( Imagick::INTERLACE_PLANE ); // True - line interlace output.
} else {
$this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); // False - no interlace output.
}
}
$write_image_result = $this->write_image( $this->image, $filename ); $write_image_result = $this->write_image( $this->image, $filename );
if ( is_wp_error( $write_image_result ) ) { if ( is_wp_error( $write_image_result ) ) {
return $write_image_result; return $write_image_result;
@ -833,6 +846,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
try { try {
// Reset original format. // Reset original format.
$this->image->setImageFormat( $orig_format ); $this->image->setImageFormat( $orig_format );
if ( isset( $orig_interlace ) ) {
$this->image->setInterlaceScheme( $orig_interlace );
}
} catch ( Exception $e ) { } catch ( Exception $e ) {
return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-alpha-57606'; $wp_version = '6.5-alpha-57607';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.