Automattic / regenerate-thumbnails

WordPress plugin for regenerating thumbnails of uploaded images. Over 1 million active users and counting.
https://alex.blog/wordpress-plugins/regenerate-thumbnails/
GNU General Public License v2.0
133 stars 54 forks source link

Unexpected behaviour when new size is larger than full image #86

Open smerriman opened 4 years ago

smerriman commented 4 years ago

Suppose a site has post thumbnails set to 200x200; I change this to 600x600 and regenerate thumbnails (telling the plugin to skip correctly sized images).

If after doing so, I upload a new 400x400 image, the post-thumbnail size won't get created in the metadata (since it is too small), so when the theme calls the_post_thumbnail(), it will output the full 400x400 image.

However, if a 400x400 image was uploaded prior to regeneration, when the theme calls the_post_thumbnail, it will output the original 200x200 image.

This is because the plugin is skipping the thumbnail size ('thumbnail would be larger than original'), but leaving the old size in the metadata, rather than removing it.

I believe removing it would be the logical behaviour.

ddur commented 4 years ago

AFAIK, WP 5.3 and above will clear all metadata[sizes] on upload and on regenerate

smerriman commented 4 years ago

No, this is nothing to do with the WP version (it would in fact be very bad if it cleared the metadata in general, since it's often important to have unregistered sizes).

ddur commented 4 years ago

https://github.com/WordPress/WordPress/blob/618329a7504958c58b2bd9898bdd8c49d65d386e/wp-admin/includes/image.php#L239

smerriman commented 4 years ago

This is a bug report for the Regenerate Thumbnails plugin. It adds the sizes back in after calling the core WordPress function:

https://github.com/Automattic/regenerate-thumbnails/blob/master/includes/class-regeneratethumbnails-regenerator.php#L199

As mentioned, adding these sizes back is a vital part of the plugin - for example, at the point you upload a Site Icon to WordPress, it adds some square sizes to the metadata unique to that image so that it doesn't need to register a size and have it generated for your entire Media library. If these weren't readded, Site Icons would break after using this plugin.

So that section of the code shouldn't be removed; unregistered sizes should be re-added, but registered sizes - which may not exist in the new metadata due to the fact the original image isn't large enough - shouldn't.