Upload: Exclude PNG images from scaling after uploading. Fixes a case where resizing a very large PNG may create a scaled image that has smaller dimensions but larger file size than the original.

Props azaozz.
Merges [46809] to the 5.3 branch.
Fixes #48736.
Built from https://develop.svn.wordpress.org/branches/5.3@46834


git-svn-id: http://core.svn.wordpress.org/branches/5.3@46634 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-12-09 12:04:02 +00:00
parent 33da7d7e7f
commit d6875bc495
2 changed files with 76 additions and 67 deletions

View File

@ -244,6 +244,9 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
$image_meta['image_meta'] = $exif_meta;
}
// Do not scale (large) PNG images. May result in sub-sizes that have greater file size than the original. See #48736.
if ( $imagesize['mime'] !== 'image/png' ) {
/**
* Filters the "BIG image" threshold value.
*
@ -256,7 +259,12 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
* @since 5.3.0
*
* @param int $threshold The threshold value in pixels. Default 2560.
* @param array $imagesize Indexed array of the image width and height (in that order).
* @param array $imagesize {
* Indexed array of the image width and height in pixels.
*
* @type int $0 The image width.
* @type int $1 The image height.
* }
* @param string $file Full path to the uploaded image file.
* @param int $attachment_id Attachment post ID.
*/
@ -329,6 +337,7 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
}
}
}
}
// Initial save of the new metadata.
// At this point the file was uploaded and moved to the uploads directory
@ -541,7 +550,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
*
* @since 4.7.0
*
* @param array $fallback_sizes An array of image size names.
* @param string[] $fallback_sizes An array of image size names.
* @param array $metadata Current attachment metadata.
*/
$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3.1-alpha-46833';
$wp_version = '5.3.1-alpha-46834';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.