Introduction
When we change our WordPress themes, we often forget that default image sizes have changed too. As most plugins to resize WordPress images don't remove the current resized images, our wp-content/uploads
or wp-content/blog.dir
directories become full of abandoned images resulting in wasted disk space.
The command lines below will remove current resized images, including Retina versions so that we can correctly resize WordPress images per the new theme dimensions. And yes, we're using the command line, because I (Michael) am old school.
SHOW all resized images
[code]cd /home/example/public_html/wp-content/uploads
find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f
cd /home/example/public_html/wp-content/blogs.dir
find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f[/code]
DELETE all resized images
[code]cd /home/example/public_html/wp-content/uploads
find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {} \;
cd /home/example/public_html/wp-content/blogs.dir
find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {} \;[/code]
Rebuild to Resize WordPress Images
After deleting the resized media images, we can regenerate the sizes needed by using the Regenerate Thumbnails or AJAX Thumbnail Rebuild WordPress plugins.
This article was originally written in September 2011 and has been updated since for clarity.
![Michael Cannon, Director of Intelligent Automation](https://www.axelerant.com/hubfs/Michael.jpg)
Michael Cannon, Director of Intelligent Automation
Living remotely in Taiwan with 4 incredible sons, 3 playful cats, and one fiery partner. As Director of Intelligent Automation @Axelerant, they are dedicated to building trust in Axelerant as your go-to agency partner through their journey in #Automation, #Empowerment, and #Productivity.