AJAX Thumbnail Rebuild recreates the resized copies WordPress makes of every image in your media library. It does them one image at a time, so a library of any size gets through without running into the script timeout that stops the plugins which rebuild everything in a single request.
You need this whenever the sizes change: a new theme with different dimensions, a plugin that registers a size of its own, or a size you have edited yourself. WordPress applies those to images uploaded afterwards and leaves everything already in the library at its old dimensions. Rebuilding fills the gap.
On its screen under Tools you can:
- Pick which of the registered sizes to rebuild, so a single changed size does not mean redoing all of them.
- Rebuild only the images used as a featured image - which covers WooCommerce product images and product galleries - or only the file names matching a pattern, e.g.
banner-*.jpg.
- Watch it run: a progress bar, the image being worked on, a Stop button, and a list of anything it had to skip.
- See every image size registered on the site with its dimensions and crop setting.
- Clean up the resized files left behind by sizes that no longer exist.
You can also work on one image at a time without leaving the media library: a row action rebuilds or optimises a single image, a bulk action hands a selection to the plugin's screen, and the attachment details panel - wherever it opens - rebuilds, optimises, or
replaces the file. A replaced image keeps its id, title and address, so every post and product already pointing at it shows the new picture.
Beyond rebuilding, each of these is off until you turn it on:
- Uploads. How hard WordPress compresses the copies it writes, and how large an image may stay before it is scaled down.
- Optimising. Makes files smaller without resizing them, using the optimisers installed on the server - jpegoptim, optipng, gifsicle, and pngquant where lossy PNG is allowed. Where a host has none, TinyPNG or ShortPixel can do the same job over their API. A file is replaced only when the new one is genuinely smaller.
- AVIF and WebP copies. Written next to every image WordPress generates and served through a picture element, AVIF first, WebP after it, the original as the fallback - which works behind a page cache.
- Background processing. Optimising and the copies are the slow half of an upload. Queue them instead, and the upload finishes as soon as the sizes are written - on Action Scheduler where the site has it, on WP-Cron where it does not.
- Image proxy. Front end image URLs can be served through wsrv.nl, which resizes and re-encodes on the fly and serves the result from a CDN. Your own files are never touched.
- Sizes on demand. An upload keeps only its own file, and each size is cut the first time something asks for it.
This plugin requires JavaScript to be enabled.
Contributions are welcome at
Github
Upload the plugin to your blog, activate it, done. Everything is under Tools -> Rebuild Thumbnails: the rebuild screen itself, the registered sizes, cleanup, and a tab per group of settings.
2.1.0
- New setting When the work happens, under Optimising: optimising and the WebP and AVIF copies can be queued instead of run on upload, so an upload finishes as soon as the resized copies are written. The queue runs on Action Scheduler where the site has it and on WP-Cron where it does not.
- New filters
ajax_thumbnail_rebuild_background_enabled and ajax_thumbnail_rebuild_use_action_scheduler.
2.0.1
- New filter
ajax_thumbnail_rebuild_serve_copies. Return false to keep writing the WebP and AVIF copies while the front end serves the originals, for a site where a CDN or the server itself hands the copies out.
2.0.0
The whole plugin has been worked through: one 430 line file is now a set of
classes, the browser talks to a REST API of its own instead of admin-ajax, and
the screen is built from the components WordPress itself ships.
The screen:
- A tab each for rebuilding, the registered sizes, cleanup, and one per group of
settings, so no page is a wall of fields.
- Rebuilt out of tabs, list tables, postboxes and notices, with a progress bar,
a running preview, a Stop button and a list of anything it had to skip.
- A "Registered sizes" tab listing every image size on the site with its
dimensions and crop setting.
- Rebuild only the images whose file name matches a pattern, e.g.
banner-*.jpg.
- Rebuild straight from the media library: a row action for one image, and a
bulk action that hands the selection to the plugin's screen, where it runs one
image at a time.
- Rebuild, optimise or replace an image from the attachment details, wherever
they open - the media library, the grid, or the modal inside the post editor -
without leaving the page you are on.
- Replace an image by uploading a new file. The attachment keeps its id, its
title and its address, so every post and product already pointing at it shows
the new picture; the sizes are cut again and what the old picture left behind
is deleted. The new file has to be the same kind of image, which is what keeps
the links working.
- "Only rebuild featured images" also covers the images in a WooCommerce product
gallery. A product's main image is its featured image, so that was already
included.
New, all off by default:
- Upload settings. How hard WordPress compresses the copies it writes, and
how large an image may stay before it is scaled down - both of which WordPress
decides for you and gives no screen for. Set the size to 0 to keep uploads
exactly as they arrive.
- Optimising. Makes files that are already the right size smaller, using the
optimisers installed on the server - jpegoptim, optipng, gifsicle, and
pngquant when a site allows lossy PNG. They re-pack a file rather than
re-encode it, which is where the saving is; where none is installed the plugin
says so and falls back to re-encoding with PHP's own library. Nothing is
resized, a file is replaced only when the new one is genuinely smaller, and
the untouched original beside a scaled upload is left alone unless a site asks
for it. Where a host has no optimiser and will not run one, TinyPNG or
ShortPixel can do the same job over their API. Runs on upload, over the
library, or on single images from the media library.
- AVIF and WebP copies. Every image WordPress generates gets a copy written
next to it in either format, and the front end serves them through a picture
element - AVIF first, WebP after it, the original as the fallback - which
works behind a page cache. Each format has a switch and a quality of its own,
a copy that would be larger than the original is discarded, and the copies are
deleted with the attachment. AVIF is the smaller of the two and the slower to
encode; where the server's image library cannot write it, the screen says so
and the WebP copies go on being served.
- Image proxy. Front end image URLs can be served through wsrv.nl, which
resizes and re-encodes on the fly and serves the result from a CDN. Your own
files are never touched.
- Sizes on demand. An upload keeps only its own file and each size is cut
the first time something asks for it - either for every size, or for single
sizes ticked off one by one, which a rebuild then skips.
- Cleanup. Finds the resized files nothing points at any more - the ones
left behind every time an image size changes - and deletes them after you have
looked at the list. The scan only reads; a file that is an attachment of its
own, or an AVIF or WebP copy of a file still in use, is never listed.
Fixed:
- Rebuilding no longer throws away the rest of the attachment metadata.
original_image and filesize survive, so WordPress can still find and
delete the untouched upload (props @toolshedlabs-hash).
- Sub sizes are cut from the original image rather than from the "-scaled" copy,
which used to leave a duplicate set of files behind.
- Selecting a subset of sizes rebuilt every size anyway.
- Sizes registered through the
intermediate_image_sizes_advanced filter are
picked up; the filter now receives the metadata and attachment id core passes
it.
- "Toggle all" checks or clears every size instead of inverting each one.
- The button on a single attachment works when several attachments are on
screen; it no longer prints a copy of the whole script per image.
- An image whose file is missing or unreadable is skipped and listed, instead of
stalling the run.
- PHP 8.4 compatible; undefined variables, unchecked
getimagesize() results
and unescaped output cleaned up throughout.
1.14
- Fix security issues (props @patchstack)
- Fix Github link (props @Julix91 @garretthyder)
- Fix crop-settings for additional sizes (props @karlkowald)
1.2.2
- Compatibility with PHP 7.2 (props @thomas-gordon)
- Implemented throttling and retries for image regeneration (props @da2x)
1.2.1
1.2
1.12
- FIX: An issue where rebuilding thumbnails in the media gallery
would not work
1.11
- FIX: An issue where the plugin would sometimes break the media gallery.
1.10
- NEW: Rebuild thumbnails of single images on the media attachment page.
1.09
- NEW: Checkboxes can be activated by clicking on text.
1.08
- NEW: Slovak translation, provided by Branco Radenovich.
1.07
- FIX: Don't create metadata with empty size when original image is smaller
than the target size.
1.06
- FIX: Don't forget metadata for sizes that aren't rebuilt.
- FIX: Option to only rebuild featured images should now work correctly.
- FIX: Don't fail if there are no attachments.
- NEW: It's now possible to toggle all selected sizes.
- NEW: Added translation: German.
1.05
- Add option to only rebuild post thumbnails (featured images)
1.04
- Tested with Wordpress 3.2
1.03
- Fixed: Show correct height value for thumbnails.
1.02
- You can now select which thumbnail sizes you want to rebuild. Thanks to Nicolas Juen!
1.01
- Tested with Wordpress 3.0
1.0