--- image-orig.module	Fri Feb 29 15:45:11 2008
+++ image-new.module	Fri Feb 29 15:45:11 2008
@@ -96,6 +96,31 @@
     '#default_value' => variable_get('image_default_path', 'images'),
     '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored. Do not include trailing slash.', array('%dir' => variable_get('file_directory_path', 'files'))),
   );
+// look for image module extensions
+// store as function name => extension description
+$extensions = array();
+foreach (module_list() as $name => $v) {
+  if (module_hook($name, 'imagepath')) {
+    $minfo = _module_parse_info_file(drupal_get_path('module', $name). '/' . $name . '.info');
+    // get the name of the function to get the path
+    $extensions[$name] = $minfo['name'] . ' (' . $minfo['description'] . ')';
+  }
+}
+if (count($extensions) > 0) {
+  $options = array('default' => t('use default images method'));
+  foreach($extensions as $k => $v) {
+    $options[$k] = $v;
+  }
+  
+  // we have one or more extension modules; show radios for choice
+  $form['paths']['path_extension'] = array(
+    '#type' => 'radios',
+    '#title' => t('Filepath extensions'),
+    '#default_value' => variable_get('image_path_extension', 'default'),
+    '#options' => $options,
+    '#description' => t('Select an extended file storage method, or use the default image path.'),
+  );
+}
 
   $form['image_max_upload_size'] = array(
     '#type' => 'textfield',
@@ -237,6 +262,10 @@
     drupal_set_message(t('Changes to the images sizes mean that the derivative images will need to be regenerated.'));
     $form_values['image_updated'] = time();
   }
+  
+  //save path extension and function name
+  $name = $form_values['path_extension'];
+  variable_set('image_path_extension', $name);
 
   return system_settings_form_submit($form_id, $form_values);
 }
@@ -959,6 +988,7 @@
     $destination = _image_filename($original_path, $key, $temp);
 
     $status = FALSE;
+
     switch ($size['operation']) {
       // Depending on the operation, the image will be scaled or resized & cropped
       case 'scale':
@@ -992,9 +1022,24 @@
  * Creates an image filename.
  */
 function _image_filename($filename, $label = IMAGE_ORIGINAL, $temp = FALSE) {
-  $path = variable_get('image_default_path', 'images') .'/';
-  if ($temp) {
-    $path .= 'temp/';
+  $extension = variable_Get('image_path_extension', 'default');
+  if (($extension != 'default') && !$temp) {
+    // use hased directory for storage and create the path, if needed
+    // get the name of the path fetcher function
+    $path_fetcher = $extension . '_imagepath';
+    // call it to get the path
+    $path = $path_fetcher($filename, $err_text);
+    if (!$path) {
+      // failed
+      drupal_set_message($err_text, 'error');
+    }
+    $path .= '/';   // put a tail on it
+  } else {
+    // use default method
+    $path = variable_get('image_default_path', 'images') .'/';
+    if ($temp) {
+      $path .= 'temp/';
+    }
   }
 
   $filename = basename($filename);
