Ticket #28154: 28154.diff
File 28154.diff, 5.3 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class-wp-image-editor-gd.php
114 114 $this->update_size( $size[0], $size[1] ); 115 115 $this->mime_type = $size['mime']; 116 116 117 return $this->set_quality( $this->quality );117 return true; 118 118 } 119 119 120 120 /** … … 387 387 return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); 388 388 } 389 389 elseif ( 'image/jpeg' == $mime_type ) { 390 if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this-> quality) ) )390 if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) 391 391 return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); 392 392 } 393 393 else { … … 435 435 return imagegif( $this->image ); 436 436 default: 437 437 header( 'Content-Type: image/jpeg' ); 438 return imagejpeg( $this->image, null, $this-> quality);438 return imagejpeg( $this->image, null, $this->get_quality() ); 439 439 } 440 440 } 441 441 -
src/wp-includes/class-wp-image-editor-imagick.php
143 143 if ( is_wp_error( $updated_size ) ) 144 144 return $updated_size; 145 145 146 return $this->set_quality( $this->quality );146 return true; 147 147 } 148 148 149 149 /** … … 160 160 if ( is_wp_error( $quality_result ) ) { 161 161 return $quality_result; 162 162 } else { 163 $quality = $this-> quality;163 $quality = $this->get_quality(); 164 164 } 165 165 166 166 try { -
src/wp-includes/class-wp-image-editor.php
16 16 protected $size = null; 17 17 protected $mime_type = null; 18 18 protected $default_mime_type = 'image/jpeg'; 19 protected $quality = 90; 19 protected $quality = false; 20 protected $default_quality = 90; 20 21 21 22 /** 22 23 * Each instance handles a single file. … … 203 204 } 204 205 205 206 /** 206 * SetsImage Compression quality on a 1-100% scale.207 * Gets the Image Compression quality on a 1-100% scale. 207 208 * 208 * @since 3.5.0209 * @since 4.0.0 209 210 * @access public 210 211 * 211 * @param int $quality Compression Quality. Range: [1,100] 212 * @return boolean|WP_Error True if set successfully; WP_Error on failure. 212 * @return int $quality Compression Quality. Range: [1,100] 213 213 */ 214 public function set_quality( $quality = null ) { 215 if ( $quality == null ) { 216 $quality = $this->quality; 217 } 218 219 /** 220 * Filter the default image compression quality setting. 221 * 222 * @since 3.5.0 223 * 224 * @param int $quality Quality level between 1 (low) and 100 (high). 225 * @param string $mime_type Image mime type. 226 */ 227 $quality = apply_filters( 'wp_editor_set_quality', $quality, $this->mime_type ); 228 229 if ( 'image/jpeg' == $this->mime_type ) { 214 public function get_quality() { 215 if ( ! $this->quality ) { 230 216 /** 231 * Filter the JPEG compression quality for backward-compatibility.217 * Filter the default image compression quality setting. 232 218 * 233 * The filter is evaluated under two contexts: 'image_resize', and 'edit_image', 234 * (when a JPEG image is saved to file). 219 * @since 3.5.0 235 220 * 236 * @since 2.5.0 237 * 238 * @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG. 239 * @param string $context Context of the filter. 221 * @param int $quality Quality level between 1 (low) and 100 (high). 222 * @param string $mime_type Image mime type. 240 223 */ 241 $quality = apply_filters( ' jpeg_quality', $quality, 'image_resize');224 $quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type ); 242 225 243 // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility. 244 if ( $quality == 0 ) { 245 $quality = 1; 226 if ( 'image/jpeg' == $this->mime_type ) { 227 /** 228 * Filter the JPEG compression quality for backward-compatibility. 229 * 230 * The filter is evaluated under two contexts: 'image_resize', and 'edit_image', 231 * (when a JPEG image is saved to file). 232 * 233 * @since 2.5.0 234 * 235 * @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG. 236 * @param string $context Context of the filter. 237 */ 238 $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' ); 239 240 if ( ! $this->set_quality( $quality ) ) { 241 $this->quality = $this->default_quality; 242 } 246 243 } 247 244 } 248 245 249 if ( ( $quality >= 1 ) && ( $quality <= 100 ) ){ 246 return $this->quality; 247 } 248 249 /** 250 * Sets Image Compression quality on a 1-100% scale. 251 * 252 * @since 3.5.0 253 * @access public 254 * 255 * @param int $quality Compression Quality. Range: [1,100] 256 * @return boolean|WP_Error True if set successfully; WP_Error on failure. 257 */ 258 public function set_quality( $quality = null ) { 259 $quality = $this->quality; 260 261 // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility. 262 if ( $quality == 0 ) { 263 $quality = 1; 264 } 265 266 if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) { 250 267 $this->quality = $quality; 251 268 return true; 252 269 } else {