[wp-trac] [WordPress Trac] #29903: possible bug in class-wp-image-editor.php (get_quality method)

WordPress Trac noreply at wordpress.org
Thu Oct 9 14:13:06 UTC 2014


#29903: possible bug in class-wp-image-editor.php (get_quality method)
--------------------------+-----------------------------
 Reporter:  jdanoz        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  3.5
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hello,

 I've been checking the code about WP_Image_Editor, and related classes.

 Inside class-wp-image-editor.php, you have the abstract class
 WP_Image_Editor, with several method definitions that implementations of
 the editor should rewrite/define/implement/override.

 If you have a look to the get_quality method, that is used to get the
 Image Compression quality for a given instance.

 if the $quality attribute of the class is not set (default is (bool)
 false, then we try to get the quality using the filter
 "wp_editor_set_quality". We then retrieve the value and we keep it inside
 $quality.

 Then after that, if image is jpeg (mime_type), we retrieve the quality
 using the filter "jpeg_quality", and then we set the $quality attribute of
 the current object using this $quality value.

 For the case of the image being a jpeg is okay, but in the case the mime
 type will be other than jpeg, the $quality attibute is not set.

 I think this is a bug.

 I put here the code:

 {{{

         /**
          * Gets the Image Compression quality on a 1-100% scale.
          *
          * @since 4.0.0
          * @access public
          *
          * @return int $quality Compression Quality. Range: [1,100]
          */
         public function get_quality() {
                 if ( ! $this->quality ) {
                         /**
                          * Filter the default image compression quality
 setting.
                          *
                          * @since 3.5.0
                          *
                          * @param int    $quality   Quality level between
 1 (low) and 100 (high).
                          * @param string $mime_type Image mime type.
                          */
                         $quality = apply_filters( 'wp_editor_set_quality',
 $this->default_quality, $this->mime_type );

                         if ( 'image/jpeg' == $this->mime_type ) {
                                 /**
                                  * Filter the JPEG compression quality for
 backward-compatibility.
                                  *
                                  * The filter is evaluated under two
 contexts: 'image_resize', and 'edit_image',
                                  * (when a JPEG image is saved to file).
                                  *
                                  * @since 2.5.0
                                  *
                                  * @param int    $quality Quality level
 between 0 (low) and 100 (high) of the JPEG.
                                  * @param string $context Context of the
 filter.
                                  */
                                 $quality = apply_filters( 'jpeg_quality',
 $quality, 'image_resize' );

                                 if ( ! $this->set_quality( $quality ) ) {
                                         $this->quality =
 $this->default_quality;
                                 }
                         }
                 }

                 return $this->quality;
         }


 }}}

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


More information about the wp-trac mailing list