--- update-image-derivatives.php?rev=1.1	2005-05-02 09:27:32.000000000 -0400
+++ update-image-derivatives.php	2005-05-02 08:41:25.000000000 -0400
@@ -0,0 +1,96 @@
+<?php
+/**
+ * Script: update-image-derivatives.php
+ * Script version: $Id: update-image-derivatives.php,v 1.1 2005/04/27 16:52:24 njivy Exp $
+ *
+ * Author: Nic Ivy (nji@njivy.org)
+ * Date started: 27 April 2005
+ *
+ * Drupal version: 4.6.0
+ *
+ * Instructions: 
+ *  1) Back up your images and your database.
+ *  2) Run update-image.php first.
+ *  3) Edit the configurable values below.
+ *    1) $minimum_nid is the node ID at which this script will start checking.  
+ *       Smaller nids will be ignored.
+ *    2) $nodes_per_run is how many nodes to check per page load.
+ *  3) Copy this file to your Drupal installation root and run it from a web browser.
+ *  4) Reload this page as necessary.
+ *
+ * Warning:
+ *  This script is provided AS-IS.  It could screw up your data,
+ *  so be careful.  Backups are recommend.
+ *
+ */
+
+include_once 'includes/bootstrap.inc';
+include_once 'includes/common.inc';
+
+#$minimum_nid = NULL;
+#$nodes_per_run = NULL;
+
+//----- Configurable -----
+$minimum_nid = 29;
+$nodes_per_run = 10;
+//------------------------
+
+$successes = 0;
+$sizes = _image_get_sizes();
+$this_run = $nodes_per_run;
+
+print "Updating image data by creating missing image sizes<br />
+minimum nid: $minimum_nid<br />
+nodes per run: $nodes_per_run<br />
+<hr />
+";
+
+$time = microtime();
+$time = explode(' ', $time);
+$start = $time[1] + $time[0];
+
+$result = db_query('SELECT nid, COUNT(filename) AS count FROM {files} WHERE nid >= ' . $minimum_nid . ' GROUP BY nid ORDER BY nid');
+while (($pre_row = db_fetch_object($result)) && $this_run > 0) {
+  if ($pre_row->nid && $pre_row->count < 3) {
+    $row  = db_fetch_object(db_query('SELECT * FROM {files} WHERE nid = ' . $pre_row->nid . ' AND filename = "_original"'));
+    $info = image_get_info('files/'.$row->filepath);
+
+    print "nid: $pre_row->nid ... $row->filepath ... " . '(w=' . $info['width'] . ', h=' . $info['height'] . ') <br />';
+  
+    foreach ($sizes as $size) {
+      $file = NULL;
+      $filesize = NULL;
+      if ($size['label'] && $size['width'] && $size['height']) {
+        if ($info['width'] > $size['width'] || $info['height'] > $size['height']) {
+          $filename = _image_filename(basename($row->filepath), $size['label']);
+
+          if (!image_scale('files/'.$row->filepath, file_create_path($filename), $size['width'], $size['height'])) {
+            print '<i>Unable to create ' . $size['label'] . "</i><br />\n";
+          }
+          else {
+            $fid = db_next_id('{files}_fid');
+            $filesize = filesize(file_create_path($filename));
+            db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', '%d', %d)",
+                     $fid, $row->nid, $size['label'], file_create_path($filename), $row->filemime, $filesize, 0);
+            print '<i>Created ' . $size['label'] . "</i><br />\n";
+            $successes++;
+          }
+        }
+      }
+    }
+    $this_run--;
+  }
+}
+
+$time = microtime();
+$time = explode(' ', $time);
+$finish = $time[1] + $time[0];
+$time = round(($finish - $start), 2);
+
+print "<br /><hr />
+execution time: approximately $time seconds<br />
+$successes images created successfully<br />
+nodes this run: " . ($nodes_per_run - $this_run) . "<br />
+your user ID: $user->uid<br />
+";
+?>
