Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.19.2.35
diff -u -r1.19.2.35 imagecache.module
--- imagecache.module	30 Mar 2008 21:15:37 -0000	1.19.2.35
+++ imagecache.module	14 Apr 2008 04:54:38 -0000
@@ -346,10 +346,10 @@
 function _imagecache_filter($key, $value, $current_width, $current_height, $new_width = NULL, $new_height = NULL) {
   switch ($key) {
     case 'width':
-      $value = _imagecache_percent_filter($value, $current_width);
+      $value = _imagecache_dimension_filter($value, $current_width);
       break;
     case 'height':
-      $value = _imagecache_percent_filter($value, $current_height);
+      $value = _imagecache_dimension_filter($value, $current_height);
       break;
     case 'xoffset':
       $value = _imagecache_keyword_filter($value, $current_width, $new_width);
@@ -364,10 +364,29 @@
 /**
  * Accept a percentage and return it in pixels.
  */
-function _imagecache_percent_filter($value, $current_pixels) {
+// CANARY: changed the function name (fr. '_imagecache_percent_filter') to accept more filters
+function _imagecache_dimension_filter($value, $current_pixels) {
   if (strpos($value, '%') !== FALSE) {
     $value = str_replace('%', '', $value) * 0.01 * $current_pixels;
   }
+  //CANARY BEGIN: add filter to snap to a multiple of X pixels
+  /* use: allows you to enter a baseline (snap) value as well as an integer or %
+  *  ex: 'snap-18' will round down to the nearest multiple on 18px
+  *  ex: 'snap-15' will round down to the nearest multiple on 15px */
+  if (strpos($value, 'snap-') !== FALSE) {
+    $snap = str_replace('snap-', '', $value);
+    $nearest_snap = floor($current_pixels / $snap);
+    $value = $snap * $nearest_snap;
+  }
+  /* add filter to to remove X pixels (for a border in a grid-based layout)
+  * ex: 'remove-10' will remove 10px (allowing for a 5px border on either side) 
+  * use: corp or otherwise size your image to the dimensions of your grid, 
+  * then add a remove value to precisely fit the image+border in the grid */
+  if (strpos($value, 'remove-') !== FALSE) {
+    $remove = str_replace('remove-', '', $value);
+    $value = $current_pixels - $remove;
+  }
+  //CANARY END
   return $value;
 }
 
@@ -663,13 +682,13 @@
           '#type' => 'textfield',
           '#title' => t('Width'),
           '#default_value' => $action['data']['width'],
-          '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
+          '#description' => t('Enter a width in pixels, a percentage, snap, or remove value. i.e. 500, 80%, snap-10, or remove-10.'),
         );
         $form[$actionid]['data']['height'] = array(
           '#type' => 'textfield',
           '#title' => t('Height'),
           '#default_value' => $action['data']['height'],
-          '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
+          '#description' => t('Enter a height in pixels, a percentage, snap, or remove value. i.e. 500, 80%, snap-10, or remove-10.'),
         );
         break;
       case 'crop':
@@ -677,13 +696,13 @@
           '#type' => 'textfield',
           '#title' => t('Width'),
           '#default_value' => $action['data']['width'],
-          '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
+          '#description' => t('Enter a width in pixels, a percentage, snap, or remove value. i.e. 500, 80%, snap-10, or remove-10.'),
         );
         $form[$actionid]['data']['height'] = array(
           '#type' => 'textfield',
           '#title' => t('Height'),
           '#default_value' => $action['data']['height'],
-          '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
+          '#description' => t('Enter a height in pixels, a percentage, snap, or remove value. i.e. 500, 80%, snap-10, or remove-10.'),
         );
         $form[$actionid]['data']['xoffset'] = array(
           '#type' => 'textfield',

