Changeset 28879
- Timestamp:
- 06/28/2014 03:49:55 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-gd.php
r28640 r28879 115 115 $this->mime_type = $size['mime']; 116 116 117 return $this->set_quality( $this->quality );117 return true; 118 118 } 119 119 … … 395 395 } 396 396 elseif ( 'image/jpeg' == $mime_type ) { 397 if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this-> quality) ) )397 if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) 398 398 return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); 399 399 } … … 443 443 default: 444 444 header( 'Content-Type: image/jpeg' ); 445 return imagejpeg( $this->image, null, $this-> quality);445 return imagejpeg( $this->image, null, $this->get_quality() ); 446 446 } 447 447 } -
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r28513 r28879 144 144 return $updated_size; 145 145 146 return $this->set_quality( $this->quality );146 return true; 147 147 } 148 148 … … 161 161 return $quality_result; 162 162 } else { 163 $quality = $this-> quality;163 $quality = $this->get_quality(); 164 164 } 165 165 -
trunk/src/wp-includes/class-wp-image-editor.php
r28320 r28879 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 /** … … 204 205 205 206 /** 207 * Gets the Image Compression quality on a 1-100% scale. 208 * 209 * @since 4.0.0 210 * @access public 211 * 212 * @return int $quality Compression Quality. Range: [1,100] 213 */ 214 public function get_quality() { 215 if ( ! $this->quality ) { 216 /** 217 * Filter the default image compression quality setting. 218 * 219 * @since 3.5.0 220 * 221 * @param int $quality Quality level between 1 (low) and 100 (high). 222 * @param string $mime_type Image mime type. 223 */ 224 $quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type ); 225 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 } 243 } 244 } 245 246 return $this->quality; 247 } 248 249 /** 206 250 * Sets Image Compression quality on a 1-100% scale. 207 251 * … … 213 257 */ 214 258 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 ) { 230 /** 231 * Filter the JPEG compression quality for backward-compatibility. 232 * 233 * The filter is evaluated under two contexts: 'image_resize', and 'edit_image', 234 * (when a JPEG image is saved to file). 235 * 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. 240 */ 241 $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' ); 242 243 // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility. 244 if ( $quality == 0 ) { 245 $quality = 1; 246 } 247 } 248 249 if ( ( $quality >= 1 ) && ( $quality <= 100 ) ){ 259 // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility. 260 if ( $quality == 0 ) { 261 $quality = 1; 262 } 263 264 if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) { 250 265 $this->quality = $quality; 251 266 return true; -
trunk/tests/phpunit/tests/image/editor.php
r25002 r28879 53 53 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 54 54 55 // Make quality readable56 $property = new ReflectionProperty( $editor, 'quality' );57 $property->setAccessible( true );58 59 55 // Ensure set_quality works 60 56 $this->assertTrue( $editor->set_quality( 75 ) ); 61 $this->assertEquals( 75, $ property->getValue( $editor) );57 $this->assertEquals( 75, $editor->get_quality() ); 62 58 63 59 // Ensure the quality filter works … … 65 61 add_filter( 'wp_editor_set_quality', $func ); 66 62 $this->assertTrue( $editor->set_quality( 75 ) ); 67 $this->assertEquals( 100, $property->getValue( $editor) );63 $this->assertEquals( 75, $editor->get_quality() ); 68 64 69 65 // Clean up
Note: See TracChangeset
for help on using the changeset viewer.