diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php index 23331c7f19..938ae61d48 100644 --- a/wp-includes/class-wp-image-editor-gd.php +++ b/wp-includes/class-wp-image-editor-gd.php @@ -504,6 +504,11 @@ class WP_Image_Editor_GD extends WP_Image_Editor { $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 ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) { return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) ); diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php index 546ad3e799..64babdad5a 100644 --- a/wp-includes/class-wp-image-editor-imagick.php +++ b/wp-includes/class-wp-image-editor-imagick.php @@ -489,10 +489,6 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { $this->image->setImageDepth( 8 ); } } - - if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) { - $this->image->setInterlaceScheme( Imagick::INTERLACE_NO ); - } } catch ( Exception $e ) { 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 ); } + 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 ); if ( is_wp_error( $write_image_result ) ) { return $write_image_result; @@ -833,6 +846,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { try { // Reset original format. $this->image->setImageFormat( $orig_format ); + if ( isset( $orig_interlace ) ) { + $this->image->setInterlaceScheme( $orig_interlace ); + } } catch ( Exception $e ) { return new WP_Error( 'image_save_error', $e->getMessage(), $filename ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index e884879323..02330a5545 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @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.