Repository navigation
Media command to remove all generated images #238
Copy link
Copy link
Closed
Labels
command:mediaRelated to 'media' commandRelated to 'media' commandcommand:media-regenerateRelated to 'media regenerate' commandRelated to 'media regenerate' commandscope:distributionRelated to distributionRelated to distribution
Description
Activity
I think it makes sense to add a command like this.
However, it should be noted that there's no guarantee that if you regenerate the thumbnails, that you'll get the exact same thumbnails with the same settings and the same quality:
- WordPress can use different image libraries depending on what the server supports. These have differing results.
- Color correction could be misconfigured on the server, resulting in different colors in the thumbnails.
- The PHP configuration for the image sizes might have been changed without rebuilding the thumbnails, so some/all of the thumbnails might not actually reflect the current configuration.
- Plugins (active, inactive or uninstalled ones) might have been used to adapt the thumbnail generation.
- The plugins might have been generated via an external service which might or might not be available from the target location.
This is a destructive operation, and although there is a good probability that regeneration will recreate what was deleted, there's no guarantee for that.
Reacted by Luke CavanaghAnalogous to
regenerate, this could be calledprune.It could have an optional flag
--remove-abandonedto get rid of thumbnails that can't be regenerated anymore.Reacted by Berliner SüdenI have some CLI code that deletes all intermediate images. Would that be of interest?
@paulschreiber I am interested, as I have a need for this.
- addedcommand:mediaRelated to 'media' commandRelated to 'media' commandcommand:media-regenerateRelated to 'media regenerate' commandRelated to 'media regenerate' commandhelp-wantedExtra attention is neededExtra attention is neededscope:distributionRelated to distributionRelated to distribution
on Mar 19, 2026
Metadata
Metadata
Assignees
Labels
command:mediaRelated to 'media' commandRelated to 'media' commandcommand:media-regenerateRelated to 'media regenerate' commandRelated to 'media regenerate' commandscope:distributionRelated to distributionRelated to distribution
Today I was cleaning up a hosting account for a freelance client by backing up and deleting sites that they no longer use. My typical process for this is to create a zip of the site's final state (including a database export and uploads directory) and tucking it away for safe keeping for a period of time.
One site had a very large uploads directory because of a large number of registered image sizes. This meant a very large ZIP file. However, after removing the generated image sizes leaving only the original, the ZIP file backup was significantly smaller. If I ever need to spin up this site again for whatever reason, I can just restore the database and run
wp media regenerate, and all of the image sizes would be present.I used
find . -name "*-*x*.*" | xargs rm -fto accomplish this (props here), but this could remove original files that happen to follow a-400x400.naming pattern. It would be great if there was a command that:Abandoned image sizes (images generated and stored in attachment meta that no longer correspond to a registered image size) would need to remain because those cannot be regenerated, but still may be linked in content.
Almost a reverse
regenerate-thumbnailscommand.