diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index 23331c7f196cc..938ae61d48b9a 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -504,6 +504,11 @@ protected function _save( $image, $filename = null, $mime_type = null ) { $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/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 546ad3e7991bf..64babdad5aece 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -489,10 +489,6 @@ protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_TRIAN $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 @@ protected function _save( $image, $filename = null, $mime_type = null ) { 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 @@ protected function _save( $image, $filename = null, $mime_type = null ) { 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 ); }