Changeset 59247
- Timestamp:
- 10/17/2024 05:03:23 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor-imagick.php
r59145 r59247 207 207 case 'image/jpeg': 208 208 $this->image->setImageCompressionQuality( $quality ); 209 $this->image->setCompressionQuality( $quality ); 209 210 $this->image->setImageCompression( imagick::COMPRESSION_JPEG ); 210 211 break; … … 215 216 // Use WebP lossless settings. 216 217 $this->image->setImageCompressionQuality( 100 ); 218 $this->image->setCompressionQuality( 100 ); 217 219 $this->image->setOption( 'webp:lossless', 'true' ); 218 220 parent::set_quality( 100 ); 219 221 } else { 220 222 $this->image->setImageCompressionQuality( $quality ); 223 $this->image->setCompressionQuality( $quality ); 221 224 } 222 225 break; … … 225 228 $this->image->setOption( 'heic:speed', 7 ); 226 229 $this->image->setImageCompressionQuality( $quality ); 230 $this->image->setCompressionQuality( $quality ); 227 231 break; 228 232 default: 229 233 $this->image->setImageCompressionQuality( $quality ); 234 $this->image->setCompressionQuality( $quality ); 230 235 } 231 236 } catch ( Exception $e ) { -
trunk/tests/phpunit/tests/media.php
r59145 r59247 5392 5392 5393 5393 /** 5394 * Test AVIF quality filters. 5395 * 5396 * @ticket 61614 5397 */ 5398 public function test_quality_with_avif_conversion_file_sizes() { 5399 $temp_dir = get_temp_dir(); 5400 $file = $temp_dir . '/33772.jpg'; 5401 copy( DIR_TESTDATA . '/images/33772.jpg', $file ); 5402 5403 $editor = wp_get_image_editor( $file ); 5404 // Only continue if the server supports AVIF. 5405 if ( ! $editor->supports_mime_type( 'image/avif' ) ) { 5406 $this->markTestSkipped( 'AVIF is not supported by the selected image editor.' ); 5407 } 5408 5409 $attachment_id = self::factory()->attachment->create_object( 5410 array( 5411 'post_mime_type' => 'image/jpeg', 5412 'file' => $file, 5413 ) 5414 ); 5415 5416 // Test sizes with AVIF images. 5417 add_filter( 'image_editor_output_format', array( $this, 'image_editor_output_avif' ) ); 5418 $avif_sizes = wp_generate_attachment_metadata( $attachment_id, $file ); 5419 remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_avif' ) ); 5420 5421 // Set the compression quality to a lower setting and test again, verifying that file sizes are all smaller. 5422 add_filter( 'image_editor_output_format', array( $this, 'image_editor_output_avif' ) ); 5423 add_filter( 'wp_editor_set_quality', array( $this, 'image_editor_change_quality_low' ) ); 5424 $smaller_avif_sizes = wp_generate_attachment_metadata( $attachment_id, $file ); 5425 remove_filter( 'wp_editor_set_quality', array( $this, 'image_editor_change_quality_low' ) ); 5426 remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_avif' ) ); 5427 5428 // Sub-sizes: for each size, the AVIF should be smaller than the JPEG. 5429 $sizes_to_compare = array_intersect_key( $avif_sizes['sizes'], $smaller_avif_sizes['sizes'] ); 5430 5431 foreach ( $sizes_to_compare as $size => $size_data ) { 5432 $this->assertLessThan( $avif_sizes['sizes'][ $size ]['filesize'], $smaller_avif_sizes['sizes'][ $size ]['filesize'] ); 5433 } 5434 } 5435 5436 /** 5394 5437 * Test that an image size isn't generated if it matches the original image size. 5395 5438 * … … 6443 6486 6444 6487 /** 6488 * Output AVIF images. 6489 */ 6490 public function image_editor_output_avif() { 6491 return array( 'image/jpeg' => 'image/avif' ); 6492 } 6493 6494 /** 6445 6495 * Changes the quality using very low quality for JPEGs and very high quality 6446 6496 * for WebPs, used to verify the filter is applying correctly. … … 6461 6511 6462 6512 /** 6513 * Output only low quality images. 6514 */ 6515 public function image_editor_change_quality_low( $quality ) { 6516 return 15; 6517 } 6518 6519 /** 6463 6520 * Change the omit loading attribute threshold value. 6464 6521 *
Note: See TracChangeset
for help on using the changeset viewer.