WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#29903 closed defect (bug) (duplicate)

possible bug in class-wp-image-editor.php (get_quality method)

Reported by: jdanoz Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Media Keywords:
Focuses: Cc:

Description

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;
	}


Change History (1)

#1 @ocean90
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version changed from 3.5 to 4.0

Duplicate of #29856.

Note: See TracTickets for help on using tickets.