Make WordPress Core

Opened 7 weeks ago

Last modified 6 weeks 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:
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 (2)

#1 @rohitmathur7
6 weeks 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 weeks 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

Note: See TracTickets for help on using tickets.