[wp-trac] [WordPress Trac] #53667: Support `wp_editor_set_quality` for both loaded and saved `mime_type`s

WordPress Trac noreply at wordpress.org
Thu Jul 15 13:18:52 UTC 2021


#53667: Support `wp_editor_set_quality` for both loaded and saved `mime_type`s
--------------------------+-----------------------------
 Reporter:  mikeschroder  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 WordPress supports setting image quality via a filter,
 `wp_editor_set_quality`.

 This filter provides the `mime_type`, which implies that the setting could
 conditionally apply to a certain MIME type only -- like in the example
 filter from [https://make.wordpress.org/core/2021/06/07/wordpress-5-8
 -adds-webp-support/ this post]:
 {{{
 // Use a quality setting of 75 for WebP images.
 function filter_webp_quality( $quality, $mime_type ) {
   if ( 'image/webp' === $mime_type ) {
      return 75;
   }
   return $quality;
 }
 add_filter( 'wp_editor_set_quality', 'filter_webp_quality', 10, 2 );
 }}}

 However, `set_quality()` applies [https://github.com/WordPress/wordpress-
 develop/blob/f17f4f5f7e474e2c0bb77ace02aaf44fccd8362c/src/wp-includes
 /class-wp-image-editor-imagick.php#L180 on load], but not on save. This
 means that if a different type is loaded than is saved (loading a JPEG,
 and saving WebP, for instance), that the filter would not apply to the
 latter `mime_type`.

 WordPress should apply the filter's details when saving as well.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53667>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list