You could create a custom module and then use hook_cron() to rebuild the imagecage.
Update
I've just spent the last hour trying to work out how to do it server-side and I think I've cracked it.
/**
* Implements hook_cron().
*/
function rebuildimagecache_cron() {
global $base_url;
// get published nodes
$result = db_query('SELECT nid FROM {node} WHERE status = 1');
while ($nodes = db_fetch_array($result)) {
$node = node_load($nodes['nid']);
$node_type = $node->type;
// get cck fields for the current nodes node_type
$fields = content_fields(NULL, $node_type);
foreach ($fields as $key => $value) {
// only deal with file fields that use the image widegt tyoe
if ($value['type'] == 'filefield' && $value['widget']['type'] == 'imagefield_widget') {
$preset_tokens = explode('_', $value['display_settings']['full']['format']);
$imagecache_preset = $preset_tokens[0];
$field_name = $value['field_name'];
// iterate over each field instance
foreach ($node->$field_name as $field_instance) {
$filepath = $field_instance['filepath'];
$cachedpath = imagecache_create_path($imagecache_preset, $filepath);
file_get_contents($base_url . base_path() . $cachedpath);
}
}
}
}
}
How it works:
- Get all the published nodes
- For each node gets the node type
- Gets an array of fields for the current node being iterated
- Iterates over all the fields and checks if any are image fields
- If image field found then get image cache preset associated
- Iterate over image field instances of node
- For each image field instance get image filepath
- Convert image file path into image cache path
- Read file path using file_get_contents() over HTTP to force image cache to generate cached image.
I've tested it and it worked great for me in Drupal 6. A Drupal 7 version would be slightly more tricky due to the changes in the underlying File API.
You'll have to create a custom module and paste this function in. Make sure you also change the hook name from rebuildimagecache
to the name of your custom module.
I've used hook_cron()
so that it will run when cron is ran but you could run it manually via a drush
command.