Ticket #37840: 37840.2.diff
File 37840.2.diff, 8.2 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/image.php
diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 254ba7d90f..f69ef60397 100644
a b function wp_generate_attachment_metadata( $attachment_id, $file ) { 105 105 $sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] ); 106 106 } else { 107 107 // For default sizes set in options 108 $sizes[ $s ]['width'] = get_option( "{$s}_size_w" );108 $sizes[ $s ]['width'] = get_option( "{$s}_size_w", $metadata['width'] ); 109 109 } 110 110 111 111 if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) { … … function wp_generate_attachment_metadata( $attachment_id, $file ) { 113 113 $sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] ); 114 114 } else { 115 115 // For default sizes set in options 116 $sizes[ $s ]['height'] = get_option( "{$s}_size_h" );116 $sizes[ $s ]['height'] = get_option( "{$s}_size_h", $metadata['height'] ); 117 117 } 118 118 119 119 if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) { … … function wp_generate_attachment_metadata( $attachment_id, $file ) { 121 121 $sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop']; 122 122 } else { 123 123 // For default sizes set in options 124 $sizes[ $s ]['crop'] = get_option( "{$s}_crop" );124 $sizes[ $s ]['crop'] = get_option( "{$s}_crop", false ); 125 125 } 126 126 } 127 127 -
src/wp-includes/class-wp-image-editor-gd.php
diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index 32f33dfa6e..e78dc15ccc 100644
a b class WP_Image_Editor_GD extends WP_Image_Editor { 109 109 imagesavealpha( $this->image, true ); 110 110 } 111 111 112 $this->filesize = @filesize( $this->file ); 112 113 $this->update_size( $size[0], $size[1] ); 113 114 $this->mime_type = $size['mime']; 114 115 … … class WP_Image_Editor_GD extends WP_Image_Editor { 239 240 $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); 240 241 $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); 241 242 243 if ( 'full' == $size ) { 244 if ( true === $this->can_save_optimised_full_size() ) { 245 $duplicate = false; 246 } 247 } 248 242 249 if ( ! is_wp_error( $image ) && ! $duplicate ) { 243 250 $resized = $this->_save( $image ); 244 251 -
src/wp-includes/class-wp-image-editor-imagick.php
diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index abb215038b..c38aa89ec5 100644
a b class WP_Image_Editor_Imagick extends WP_Image_Editor { 168 168 return new WP_Error( 'invalid_image', $e->getMessage(), $this->file ); 169 169 } 170 170 171 $this->filesize = @filesize( $this->file ); 171 172 $updated_size = $this->update_size(); 172 173 if ( is_wp_error( $updated_size ) ) { 173 174 return $updated_size; … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 457 458 $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); 458 459 $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); 459 460 461 if ( 'full' == $size ) { 462 if ( true === $this->can_save_optimised_full_size() ) { 463 $duplicate = false; 464 } 465 } 466 460 467 if ( ! is_wp_error( $resize_result ) && ! $duplicate ) { 461 468 $resized = $this->_save( $this->image ); 462 469 -
src/wp-includes/class-wp-image-editor.php
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index 26dd78d230..97485d6564 100644
a b abstract class WP_Image_Editor { 18 18 protected $default_mime_type = 'image/jpeg'; 19 19 protected $quality = false; 20 20 protected $default_quality = 82; 21 protected $filesize = null; 22 protected $minimum_filesize_difference = false; 23 protected $default_minimum_filesize_difference = 15; 24 21 25 22 26 /** 23 27 * Each instance handles a single file. … … abstract class WP_Image_Editor { 466 470 467 471 return $extensions[0]; 468 472 } 473 474 /** 475 * Gets minimum filesize difference for compressed full size images. 476 * 477 * @since 4.8.0 478 * @access public 479 * 480 * @return int $minimum_filesize_difference Minimum filesize difference. Range [0-100] 481 */ 482 public function get_minimum_filesize_difference() { 483 if ( ! $this->minimum_filesize_difference ) { 484 $this->set_minimum_filesize_difference(); 485 } 486 487 return $this->minimum_filesize_difference; 488 } 489 490 /** 491 * Sets minimum filesize difference for compressed full images, 0-100% scale. 492 * 493 * @since 4.8.0 494 * @access public 495 * 496 * @param int $minimum_filesize_difference Minimum filesize difference. Range [0-100] 497 * @return true|WP_Error True if set successfully; WP_Error on failure. 498 */ 499 public function set_minimum_filesize_difference( $minimum_filesize_difference = null ) { 500 if ( null === $minimum_filesize_difference ) { 501 /** 502 * Filters the default minimum filesize difference. Range [0-100] 503 * 504 * Applies only during initial editor instantiation, or when set_minimum_filesize_difference() is run 505 * manually without the `$minimum_filesize_difference` argument. 506 * 507 * set_minimum_filesize_difference() has priority over the filter. 508 * 509 * @since 4.8.0 510 * 511 * @param int $default_minimum_filesize_difference Minimum filesize difference. Range [0-100] 512 * @param string $mime_type Image mime type. 513 */ 514 $minimum_filesize_difference = apply_filters( 'wp_image_set_minimum_filesize_difference', $this->default_minimum_filesize_difference, $this->mime_type ); 515 516 517 if ( $minimum_filesize_difference < 0 || $minimum_filesize_difference > 100 ) { 518 $minimum_filesize_difference = $this->default_minimum_filesize_difference; 519 } 520 } 521 522 if ( ( $minimum_filesize_difference >= 0 ) && ( $minimum_filesize_difference <= 100 ) ) { 523 $this->minimum_filesize_difference = $minimum_filesize_difference; 524 return true; 525 } else { 526 return new WP_Error( 'invalid_filesize_difference', __('Attempted to set filesize difference outside of the range [1,100].') ); 527 } 528 } 529 530 /** 531 * Should we save the optimised version of the 'full' image? 532 * 533 * If we're optimising the 'full' image size then we need to compare image sizes. 534 * If the percentage of the image size decrease is greater than our set value 535 * then we should store the image. 536 * 537 * See trac ticket #37840 538 * 539 * @since 4.8.0 540 * @access protected 541 * 542 * @return bool True if we should save the image, otherwise False. 543 */ 544 protected function can_save_optimised_full_size() { 545 ob_start(); 546 $this->stream(); 547 $optimised_size = ob_get_length(); 548 ob_end_clean(); 549 550 // Make sure we've got numbers to calculate with 551 if( is_numeric( $optimised_size ) && is_numeric( $this->filesize ) ) { 552 $perc_decrease = ( ( $optimised_size - $this->filesize ) / ( $this->filesize * - 1 ) ) * 100; 553 554 if ( $this->get_minimum_filesize_difference() <= $perc_decrease ) { 555 return true; 556 } 557 } 558 559 return false; 560 } 469 561 } 470 562 -
src/wp-includes/media.php
diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index ec50703b33..be2588d660 100644
a b function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { 787 787 */ 788 788 function get_intermediate_image_sizes() { 789 789 $_wp_additional_image_sizes = wp_get_additional_image_sizes(); 790 $image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); // Standard sizes790 $image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large', 'full' ); // Standard sizes 791 791 if ( ! empty( $_wp_additional_image_sizes ) ) { 792 792 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); 793 793 } … … function get_intermediate_image_sizes() { 798 798 * @since 2.5.0 799 799 * 800 800 * @param array $image_sizes An array of intermediate image sizes. Defaults 801 * are 'thumbnail', 'medium', 'medium_large', 'large' .801 * are 'thumbnail', 'medium', 'medium_large', 'large', 'full'. 802 802 */ 803 803 return apply_filters( 'intermediate_image_sizes', $image_sizes ); 804 804 }