Automattic/regenerate-thumbnails

Existing images are not skipped

Closed this issue · 13 comments

Overview

Skip regenerating existing correctly sized thumbnails (faster). option is ignored. The images are regenerated regardless its value.

How to reproduce

  • Open the tool page and run the plugin
  • Open the media directory and observed that the thumbnails are generated.
  • Run the plugin a second time with the Skip option enabled.

What I expected to happen

  • The existing images to be skipped

What happened instead

  • The images are regenerated again. You can check the file dates to verify this.

Also reported in https://wordpress.org/support/topic/option-skip-existing-doesnt-work/

Just adding here that I checked it, and it seems the filter intermediate_image_sizes_advanced is not working as expected in Regenerate Thumbnails code.
The data is already empty when arriving on the method RegenerateThumbnails_Regenerator::filter_image_sizes_to_only_missing_thumbnails.

Checking a little the core code, it seems there were some recent changes around that filter. I imagine it's impacting that behavior in Regenerate Thumbnails.

ddur commented

Tested on plugin free site?

Tested on plugin free site?

I tested in a development environment, but it's probably happening in the latest versions of WordPress.

ddur commented

Tested on plugin free site?

I tested in a development environment, but it's probably happening in the latest versions of WordPress.

I mean: Filters may be intercepted by other plugins. Does your "development environment" include any other plugin except tested plugin?

I mean: Filters may be intercepted by other plugins. Does your "development environment" include any other plugin except tested plugin?

I tested in a new setup only with Regenerate Thumbnails activated.

ddur commented

Also reported in https://wordpress.org/support/topic/option-skip-existing-doesnt-work/

Just adding here that I checked it, and it seems the filter intermediate_image_sizes_advanced is not working as expected in Regenerate Thumbnails code. The data is already empty when arriving on the method RegenerateThumbnails_Regenerator::filter_image_sizes_to_only_missing_thumbnails.

Checking a little the core code, it seems there were some recent changes around that filter. I imagine it's impacting that behavior in Regenerate Thumbnails.

Actually, that data is always empty since WP version 5.3. Because image metadata is cleared upon entry into new WP 5.3 function wp_create_image_subsizes( and saved over existing image/thumbnails metadata.

Anyways, always regenerating existing images is not bad at all. Because some thumbnail settings may be changed, like compression quality, sharpening, color sampling and so forth.

confirm issue with intermediate_image_sizes_advanced see here:
#142 (comment)

Bug probably created by this core commit which saves the meta data with an empty sizes array before running the intermediate_image_sizes_advanced filter.

WordPress/WordPress@43ed676#diff-44594c5e0f87468956393bee5dcf1ea1eaf3addbaccec88b0cf91e5d42a8fe28L294

See wp-admin/includes/image.php lines 326-330 in case it's not obvious with the link.

ddur commented

Bug probably created by this core commit which saves the meta data with an empty sizes array before running the intermediate_image_sizes_advanced filter.

WordPress/WordPress@43ed676#diff-44594c5e0f87468956393bee5dcf1ea1eaf3addbaccec88b0cf91e5d42a8fe28L294

See wp-admin/includes/image.php lines 326-330 in case it's not obvious with the link.

@MarcGuay

That is by design, not a bug. It forced me to partially rewrite my Warp iMagick plugin at the time (Nov 4, 2019).

That is by design, not a bug.

I was referring to the bug in regenerate-thumbnails.

ddur commented

That is by design, not a bug.

I was referring to the bug in regenerate-thumbnails.

I was referring to the Core commit code your linked at. Metadata is cleared by design. It is not a bug.

WordPress/WordPress@43ed676#diff-44594c5e0f87468956393bee5dcf1ea1eaf3addbaccec88b0cf91e5d42a8fe28L294

ddur commented

Because metadata is cleared, it is not easy to find out if specific thumbnail already exist or not.

I guess there is no bug in regenerate-thumbnails (or it requires substantial redesign?).

Hey,
I have been looking into this and looks like the issue is that wp_generate_attachment_metadata resets the 'size' property in metadata to an empty array before calling the intermediate_image_sizes_advanced filter.

I have a fix here that keeps the behaviour the same as the original. But I am a bit tempted to just remove the check for metadata sizes, that I think might not be needed. I think we can discuss that in the review.