You may want to look at the plugin Regenerate Thumbnails by Viper007Bond.
Basically, this is how to do it:
function regenerateThumbnails() {
$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type="attachment" AND post_mime_type LIKE 'image/%'" );
foreach ( $images as $image ) {
$id = $image->ID;
$fullsizepath = get_attached_file( $id );
if ( false === $fullsizepath || !file_exists($fullsizepath) )
return;
if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) )
return true;
else
return false;
}
}
Note: This function is not very scalable. It will loop through all the images and regenerate thumbnails one by one, which may consume a large amount of memory. So, you may want to enhance it.
Related Posts:
- Add class name to post thumbnail
- Delete original image – keep thumbnail?
- the_post_thumbnail responsive srcset not populating with custom image size
- Set custom name for generated thumbnails
- wp_get_attachment_image_src always returns full-sized image
- What is your take: TimThumb vs. WordPress Thumbnails? The great debate [closed]
- Use thumbnail image using url of that image
- Skip posts without a thumbnail in loop
- How to change the naming of the resized image files
- get_pages – Display child then grandchild pages
- How to replace the_post_thumbnail template tag and show the first inside the post image instead
- Resizing Images to lower Disk Space Using Plugins
- Set (featured) thumbnail for post?
- How to make thumbnail images click into blog posts
- display WP image posts in Bootstrap 4 modal
- Customising the size of images served in Visual Composer elements [closed]
- How to scale up post thumbnails/featured image?
- Get Ancestor featured image
- Upload 3 different featured image sizes to WordPress
- Change size of featured image in Edit Post screen
- Use Video as Featured Image
- Media thumbnail for custom post inside post content
- Thumbnail and Featured Image With Fixed Sizes?
- Why am I getting errors in product.thumbnails.php? [closed]
- the_post_thumbnail ignores size parameter
- Is there a way to change a post’s thumbnail image(s)?
- Confused with the loop and repeating things
- WordPress thumbnail settings change
- Using concatenate with WordPress Thumbnail
- Looking for Add Title Tag on Feature Images on WP
- Is it possible to nest get_previous_post()?
- How to offset thumbnails to the center?
- Notice: Trying to get property of non-object when trying to get thumbnail URL
- Output post thumbnail (add class)
- How to set an equal image size for a Fallback Image as used for the Featured Image(dynamicly)
- How can I see where in my themes and plugins certain image sizes are used?
- How do I remove featured images and captions from a wordpress RSS feed?
- Custom image size in the_content loop
- Display featured image file size, extension, filename, type, orientation?
- Video playing from featured image?
- get_the_post_thumbnail(‘thumbnail-name’) always returns empty string
- array set title and alt in the_post_thumbnail
- Get thumbnail image according to the screen
- Displaying Post Featured Images on All Pages
- Image Alignment on Featured Images
- Trying to show link “Use as featured image” from Attachment window from t31os script
- Use Featured Image of Post as Header Image
- Recent posts on homepage: different thumbnail based on logged in status and post category
- default post thumbnail and category if there is no thumbnail and category
- How to display featured image description and title?
- Images uploaded on frontend display correctly but not in media editor.
- get_post_thumbnail does not display thumbnail
- Make image full width
- Facebook Does Not Grab Correct og:Image
- How to change thumbnail default size?
- WordPress 4.4 responsive sometimes doesn’t work
- get_the_post_thumbnail($post->ID, ‘thumbnail’); not working. How can I solve this?
- Is it possible to add the_post_thumbnail to style.css?
- Getting featured image of particular size.
- Different thumbnails for index and article page
- Smaller thumbnail in the_content
- Get post featured image id with $wpdb
- Attachment Image using wrong src?
- Unable to set Custom “Link URL” for Featured Image, and More?
- On what point (hook) does the_/has_post_thumbnail() load?
- First Image not loading on Mobile Version of Website
- Thumbnails not being generated for PDF files
- Make 1st Slide of PowerPoint file to be the Post thumbnail preview image
- Is it possible to set Featured Image using HTML?
- Set featured image from auto generated video thumbnail url php
- Use Post Title as alt text for Featured Image
- How to cropped thumbnail image without distorting it?
- WordPress default srcset with hard crop
- wp_get_attachment_metadata()[‘image_meta’] fetch WP metadata or EXIF?
- White Blank screen and issue to get thumbnail in
- Set Featured Image Based on Custom Field
- Post thumbnail on specific template
- Using lower resolution/size images for thumbnails on posts index
- Combining Post Thumbnails With Nivo Slider
- How to have featured image show in standard RSS Widget
- Link from Thumbnail to Post not working
- Featured Image metabox (postimagediv) doesn’t appears when it should
- Thumbnails not showing in blog
- Featured Image inserted through custom query, does not show up
- How to import linked images and make them featured -> automagically
- Change role’s settings influence post-thumbnail
- Wrap Featured Image in a Link
- Thumbnail images
- Automatic adding thumbnail to post
- Featured Image Thumbnail Sizing
- Featured Image Isn’t showing with cropped, How to show it?
- How to modify Media Library images DPI [ image quality down to make small in size ] [closed]
- How to add text & call to action button to featured image on homepage?
- Featured image as background in a div using headway
- php code for image fetching
- get_post_thumbnail_id() not getting correct featured image after post edited
- the_ID & wp_get_attachment_image_src(the_ID(), “medium”) blank
- How to I remove Featured Image from the Posts/Category Lists?
- How do I change the size of the feature picture of a single post?
- Close featured image modal windows with JS