Remove & Resize WordPress Images

Tags: AJAX Thumbnail Rebuild, Computer graphics, devops, Graphic design, WordPress


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, Chief Success Officer
Posted by

Michael Cannon, Chief Success Officer

Adventurous water-rat, Peichi's happy man, Drusus & Jace's baba, education & health champion, ex-bomb squad & dairy farmer