Changeset 59473
- Timestamp:
- 11/29/2024 11:46:50 PM (4 days ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-gd.php
r59413 r59473 221 221 222 222 list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; 223 224 $this->set_quality( 225 null, 226 array( 227 'width' => $dst_w, 228 'height' => $dst_h, 229 ) 230 ); 223 231 224 232 $resized = wp_imagecreatetruecolor( $dst_w, $dst_h ); … … 569 577 * 570 578 * @since 6.7.0 571 * 572 * @param int $quality Compression Quality. Range: [1,100] 579 * @since 6.8.0 The `$dims` parameter was added. 580 * 581 * @param int $quality Compression Quality. Range: [1,100] 582 * @param array $dims Optional. Image dimensions array with 'width' and 'height' keys. 573 583 * @return true|WP_Error True if set successfully; WP_Error on failure. 574 584 */ 575 public function set_quality( $quality = null ) {576 $quality_result = parent::set_quality( $quality );585 public function set_quality( $quality = null, $dims = array() ) { 586 $quality_result = parent::set_quality( $quality, $dims ); 577 587 if ( is_wp_error( $quality_result ) ) { 578 588 return $quality_result; … … 587 597 if ( ! empty( $webp_info['type'] ) && 'lossless' === $webp_info['type'] ) { 588 598 $quality = IMG_WEBP_LOSSLESS; 589 parent::set_quality( $quality );599 parent::set_quality( $quality, $dims ); 590 600 } 591 601 } -
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r59406 r59473 191 191 * 192 192 * @since 3.5.0 193 * 194 * @param int $quality Compression Quality. Range: [1,100] 193 * @since 6.8.0 The `$dims` parameter was added. 194 * 195 * @param int $quality Compression Quality. Range: [1,100] 196 * @param array $dims Optional. Image dimensions array with 'width' and 'height' keys. 195 197 * @return true|WP_Error True if set successfully; WP_Error on failure. 196 198 */ 197 public function set_quality( $quality = null ) {198 $quality_result = parent::set_quality( $quality );199 public function set_quality( $quality = null, $dims = array() ) { 200 $quality_result = parent::set_quality( $quality, $dims ); 199 201 if ( is_wp_error( $quality_result ) ) { 200 202 return $quality_result; … … 368 370 } 369 371 372 $this->set_quality( 373 null, 374 array( 375 'width' => $dst_w, 376 'height' => $dst_h, 377 ) 378 ); 379 370 380 // Execute the resize. 371 381 $thumb_result = $this->thumbnail_image( $dst_w, $dst_h ); -
trunk/src/wp-includes/class-wp-image-editor.php
r59406 r59473 241 241 * 242 242 * @since 3.5.0 243 * 244 * @param int $quality Compression Quality. Range: [1,100] 243 * @since 6.8.0 The `$dims` parameter was added. 244 * 245 * @param int $quality Compression Quality. Range: [1,100] 246 * @param array $dims Optional. Image dimensions array with 'width' and 'height' keys. 245 247 * @return true|WP_Error True if set successfully; WP_Error on failure. 246 */ 247 public function set_quality( $quality = null ) { 248 249 */ 250 public function set_quality( $quality = null, $dims = array() ) { 248 251 // Use the output mime type if present. If not, fall back to the input/initial mime type. 249 252 $mime_type = ! empty( $this->output_mime_type ) ? $this->output_mime_type : $this->mime_type; … … 261 264 * 262 265 * @since 3.5.0 266 * @since 6.8.0 Added the size parameter. 263 267 * 264 268 * @param int $quality Quality level between 1 (low) and 100 (high). 265 269 * @param string $mime_type Image mime type. 270 * @param array $size { 271 * Dimensions of the image. 272 * 273 * @type int $width The image width. 274 * @type int $height The image height. 275 * } 266 276 */ 267 $quality = apply_filters( 'wp_editor_set_quality', $default_quality, $mime_type );277 $quality = apply_filters( 'wp_editor_set_quality', $default_quality, $mime_type, $dims ? $dims : $this->size ); 268 278 269 279 if ( 'image/jpeg' === $mime_type ) { -
trunk/tests/phpunit/tests/media.php
r59415 r59473 5435 5435 5436 5436 /** 5437 * Test that the `wp_editor_set_quality` filter includes the dimensions in the `$dims` parameter. 5438 * 5439 * @ticket 54648 5440 */ 5441 public function test_wp_editor_set_quality_includes_dimensions() { 5442 // Before loading an image, set up the callback filter with the assertions. 5443 add_filter( 'wp_editor_set_quality', array( $this, 'assert_dimensions_in_wp_editor_set_quality' ), 10, 3 ); 5444 5445 $temp_dir = get_temp_dir(); 5446 $file = $temp_dir . '/33772.jpg'; 5447 copy( DIR_TESTDATA . '/images/33772.jpg', $file ); 5448 5449 $editor = wp_get_image_editor( $file ); 5450 5451 $attachment_id = self::factory()->attachment->create_object( 5452 array( 5453 'post_mime_type' => 'image/jpeg', 5454 'file' => $file, 5455 ) 5456 ); 5457 5458 // Generate all sizes. 5459 wp_generate_attachment_metadata( $attachment_id, $file ); 5460 5461 // Clean up the filter. 5462 remove_filter( 'wp_editor_set_quality', array( $this, 'assert_dimensions_in_wp_editor_set_quality' ), 10, 3 ); 5463 } 5464 5465 /** 5466 * Helper callback to assert that the dimensions are included in the `$dims` parameter. 5467 * 5468 * @param int $quality The quality level. 5469 * @param array $dims The dimensions array. 5470 */ 5471 public function assert_dimensions_in_wp_editor_set_quality( $quality, $mime_type, $dims ) { 5472 // Assert that the array has non empty width and height values. 5473 $this->assertArrayHasKey( 'width', $dims ); 5474 $this->assertArrayHasKey( 'height', $dims ); 5475 $this->assertGreaterThan( 0, $dims['width'] ); 5476 $this->assertGreaterThan( 0, $dims['height'] ); 5477 5478 return $quality; 5479 } 5480 5481 /** 5437 5482 * Test that an image size isn't generated if it matches the original image size. 5438 5483 *
Note: See TracChangeset
for help on using the changeset viewer.