Make WordPress Core

Opened 6 months ago

Last modified 3 months ago

#61925 new defect (bug)

subsizes with same dimensions are generated multiple times unnecessarily

Reported by: kkmuffme's profile kkmuffme Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:

Description

https://github.com/WordPress/wordpress-develop/blob/6.6/src/wp-admin/includes/image.php#L461

_wp_make_subsizes will generate the same file with same dimensions multiple times if multiple sizes with the same dimensions/crop are registered.
This unnecessarily slows down the uploads and often is a cause for timeouts too, if there are many sizes registered.

e.g. with WooCommerce where "woocommerce_gallery_thumbnail" might be equal to wp "thumbnail" size.

I checked trac, but couldn't find a related issue, in case there's one please close this one.

Change History (5)

#1 @rohitmathur7
6 months ago

Hii @kkmuffme ,
I tried to replicate the issue but was not able to.

These are the steps I followed:

  • Register multiple new image sizes with same dimensions but different name.
function replicate_subsizes_issue() {
	// Register multiple image sizes with the same dimensions and crop settings
	add_image_size( 'custom-size-1', 800, 600, true );
	add_image_size( 'custom-size-2', 800, 600, true );
	add_image_size( 'custom-size-3', 800, 600, true );
}
add_action( 'after_setup_theme', 'replicate_subsizes_issue' );
  • Added a new image in media library.
  • But for the new image I can only see one image in uploads with dimension 800X600.

Can you please specify the steps to replicate this?
Thanks.

#2 @kkmuffme
6 months ago

But for the new image I can only see one image in uploads with dimension 800X600.

Sorry, but obviously. How would you be able to see multiple files with the same name?
It generates the same 800x600 file multiple times.

Your replication is correct except that you incorrectly check the result. Set a breakpoint at the referenced line and you'll see that it recreates the image multiple times for 800x600

#3 @kkmuffme
3 months ago

#62388 was marked as a duplicate.

#4 @kkmuffme
3 months ago

As reported in https://core.trac.wordpress.org/ticket/62388 for "crop" it doesn't actually crop (see https://core.trac.wordpress.org/ticket/62389#ticket), so the cropped images that have identical dimensions as ones already generated can be skipped too.

This ticket was mentioned in PR #7802 on WordPress/wordpress-develop by @kkmuffme.


3 months ago
#5

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.