? imagecache/cvs
? imagecache/actions/cvs
? imagecache/po/cvs
Index: imagecache/imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.54
diff -u -p -r1.54 imagecache.module
--- imagecache/imagecache.module	21 Feb 2008 12:44:54 -0000	1.54
+++ imagecache/imagecache.module	8 Mar 2008 14:55:09 -0000
@@ -901,3 +901,73 @@ function imagecache_action_delete($actio
 }
 
 
+
+
+/**
+ * Add imagecache pipelining to the the image.module size derivatives form
+ */
+function imagecache_form_alter($form_id, &$form) {
+  if($form_id == 'image_admin_settings'){
+    // Sneak in our own little setting alongside the usual image dimensions
+    // UI layout is not perfect, but image.module hard-coded their table formatting.
+    // I want to over-ride theme_image_settings_sizes_form()
+    //
+    // image.module also slightly changed this structure and its API at one point
+    // this code against 1.209.2.51 2008/01/06
+    // test against other image.module releases
+    $sizes = function_exists('image_get_sizes') ? image_get_sizes() : _image_get_sizes();
+    $size_form = $form['image_sizes'];
+
+    $presets = imagecache_presets();
+    $imagecache_options = array(0=>"(no imagecache process)");
+    foreach($presets as $preset) {
+      $imagecache_options[$preset['presetid']] = $preset['presetname']; 
+    }
+    foreach(element_children($size_form) as $key){
+      // Hijack the layout of the 'link' column
+      $options = array();
+      $options['link'] = $form['image_sizes'][$key]['link']; 
+      $options['imagecache'] = array(
+        '#type' => 'select',
+        '#default_value' => $sizes[$key]['imagecache'],
+        '#options' => $imagecache_options,
+      );
+      // Manipulate parents to avoid 'tree' problem.
+      // This is all to work around the new image module theme_image_settings_sizes_form()
+      $options['link']['#parents'] = array('image_sizes', $key, 'link');
+      $options['imagecache']['#parents'] = array('image_sizes', $key, 'imagecache');
+      $form['image_sizes'][$key]['link'] = $options;
+      // With the right name, the imagecache setting made here will be stored as usual within the variables in a systems_setting_form.
+    }
+    $form['image_sizes']['#description'] .= t('<p>
+      Optionally, choose an <a href="!imagecache_settings">imagecache preset</a> 
+      to use to generate this derivative image. 
+      The dimensions shown here are used <em>after</em> the imagecache process,
+      so for best results, make the imagecache result the same size as that defined here.
+      </p>', array('!imagecache_settings' => url('admin/build/imagecache'))
+    );
+
+    // Capture the form submission so we can save this setting
+    $form['#submit']['imagecache_save_image_size_settings'] = array();
+  }
+}
+
+/**
+ * Implementation of hook_image_alter()
+ * 
+ * Capture the image_build_derivatives phase of image.module 
+ * and insert our own manipulations to it any time an image is manipulated. 
+ * 
+ * This runs the imagecache builder over the input file and places it in the
+ * output destination.
+ */
+function imagecache_image_alter($node, $destination, $sizename) {
+  $sizes = image_get_sizes();
+  $size_def = $sizes[$sizename];
+  // Appended to the dimensions is our 'imagecache' id value. Maybe.
+  if ($presetid = $size_def['imagecache']) {
+    $original = file_create_path($node->images['_original']);
+    $preset = imagecache_preset($presetid);
+    $result = imagecache_build_derivative($preset['actions'], $original, $destination );
+  }
+}
