I have recently added theme support for post_thumbnails with three new sizes, I wanted to resize all the old images uploaded previously. I have written my own script as follows:
function resizeImages()
{
require ( ABSPATH . 'wp-admin/includes/image.php' );
global $wpdb;
$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC");
foreach ($images as $image)
{
$fullsizepath = get_attached_file( $image->ID );
$metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
// If this fails, then it just means that nothing was changed (old value == new value)
if (wp_update_attachment_metadata( $image->ID, $metadata ))
{
echo $fullsizepath . " resized" . "<br/>";
}
}
}
The images that have been uploaded through wordpress work fine, but I have added some of my images by php. The images in question were picked up from our old site with a crawler and added to the database as children of the correct ID. I can retrieve all the images using get_children on the index.php page and on single.php, but for some reason they are not being resized. Can anyone help here?
