[00] Subset Sizes, Guide
Regenerate Thumbnails timing out or taking hours
Why regenerating thumbnails stalls on a large media library, how to finish the run with WP-CLI, and how to stop needing a bulk regenerate at all.
- Published
- Fix uses
- Subset Sizes (free)
- Reading time
- 3 min
Why a regenerate takes so long
WordPress creates every registered image size for every upload. Core registers six sizes, and your theme and plugins such as WooCommerce add their own. A regenerate repeats that work for every image in the library, so a site with 5,000 images and 12 sizes asks the server for 60,000 resizes.
Regenerate Thumbnails (opens in a new tab) sends those images to the server one at a time, from the browser tab that started the run, through the WordPress REST API. That has two consequences:
- Close the tab, or let the laptop sleep, and the run stops where it was.
- Each image is one PHP request. A large original with many sizes can run out of memory or hit the host’s time limit, and that image fails while the rest carry on.
Finish the run you’re in
If you have command line access, use WP-CLI. The plugin’s own readme recommends it over the plugin for large libraries, because it skips the HTTP request per image and can run in a screen session after you log out.
Regenerate only the sizes that are missing, rather than every size of every image:
wp media regenerate --only-missing --yes
If you changed one size, regenerate that size alone:
wp media regenerate --image_size=large --yes
When a single image keeps failing, run the command with its attachment ID, such as wp media regenerate 1234, to see the error for that file. A common cause is an original too large for PHP’s memory limit. Options for the command are on the wp media regenerate reference (opens in a new tab).
Stop needing a bulk regenerate
A regenerate exists because WordPress makes sizes at upload and nowhere else. A size added after an image was uploaded doesn’t exist for that image until something creates it.
Subset Sizes makes a missing size the first time it’s requested. When a browser asks for photo-600x400.jpg and the file isn’t there, the plugin creates it from the original, saves it in the uploads folder and records it in the attachment’s metadata. From the second request on, your web server serves the file directly.
That changes what a size change costs:
- Change a size under Settings → Media, or switch theme, and posts already published use the new dimensions. Each image is resized the first time a page shows it.
- With Lazy sizes on, uploads make only the sizes ticked under Create at upload (thumbnail and medium by default). Sizes no page uses are never written.
- Deleting size files is safe, because any size that’s requested again is made again.
Most Apache hosts with pretty permalinks need no setup. On nginx, add the try_files rule from getting started so requests for missing files reach WordPress. Tools → Site Health tells you whether that’s working.
How each setting behaves is in on-demand and lazy sizes. For a side-by-side with the plugin this guide started from, see Subset Sizes vs Regenerate Thumbnails.
When you still want sizes made in advance
Some images are used where no page request will create them, such as a newsletter template or a social card. Tick those sizes under Create at upload, or create the missing files ahead of time:
wp subset image-resizer generate --size=large,medium_large
It creates missing sizes only and leaves existing files alone, so a run that stops halfway can be started again without repeating work.