diff -urp --strip-trailing-cr ../image-orig/image.module ./image.module
--- ../image-orig/image.module	2009-03-09 03:24:33.000000000 +0100
+++ ./image.module	2009-03-23 23:15:10.000000000 +0100
@@ -862,20 +862,33 @@ function _image_build_derivatives($node,
  * Creates an image filename.
  */
 function _image_filename($filename, $label = IMAGE_ORIGINAL, $temp = FALSE) {
+  // Get default path for a new file.
   $path = file_directory_path() .'/'. variable_get('image_default_path', 'images');
   if ($temp) {
     $path .= '/temp';
   }
 
+  $original_path = dirname($filename);
   $filename = basename($filename);
 
-  // Insert the resized name in non-original images
   if ($label && ($label != IMAGE_ORIGINAL)) {
+    // Keep resized images under the same path, where original is (does not
+    // apply to temporary files, these still use the default path).
+    // Additionaly, put resized images into subdirectories, to keep the
+    // file system tidy and easy to maintain. Provide a fallback to default.
+    if (!$temp && $original_path != '.' && substr($original_path, -5) != '/temp' && substr($original_path, -4) != '/tmp') {
+      $path = $original_path .'/'. $label;
+      file_check_directory($path, TRUE);
+    }
+    else {
+      $original_path = $path;
+    }
+    // Insert the resized name in non-original images
     $pos = strrpos($filename, '.');
     if ($pos === false) {
       // The file had no extension - which happens in really old image.module
       // versions, so figure out the extension.
-      $image_info = image_get_info(file_create_path($path .'/'. $filename));
+      $image_info = image_get_info(file_create_path($original_path .'/'. $filename));
       $filename = $filename .'.'. $label .'.'. $image_info['extension'];
     }
     else {
