? test.patch
Index: image.imagemagick.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.imagemagick.inc,v
retrieving revision 1.14
diff -u -r1.14 image.imagemagick.inc
--- image.imagemagick.inc	18 Jul 2007 17:04:02 -0000	1.14
+++ image.imagemagick.inc	1 Aug 2007 20:28:34 -0000
@@ -28,19 +28,6 @@
     '#description' => t('Specify the complete path to the ImageMagic <kbd>convert</kbd> binary. For example: <kbd>/usr/bin/convert</kbd> or <kbd>C:\Program Files\ImageMagick-6.3.4-Q16\convert.exe</kbd>'),
   );
 
-  $form['imagemagick_options'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('ImageMagick Advanced Options'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-    '#description' => t('These are advanced options for controling the ImageMagick. If you do not understand what these settings do you should not change them.'),
-  );
-  $form['imagemagick_options']['image_imagemagick_option_strip'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Strip the image of any profiles or comments'),
-    '#default_value' => variable_get('image_imagemagick_option_strip', 0),
-    '#description' => t('Checking this option may reduce file sizes by removing any color profiles or comments embedded in the image. <a href="!link">More information on -strip</a>', array('!link' => url('http://www.imagemagick.org/script/command-line-options.php#strip'))),
-  );
   return $form;
 }
 
@@ -75,39 +62,56 @@
 }
 
 /**
- * Resize an image to the given width and height
+ * Invoke hook_imagemagick_alter.
+ *
+ * @param $filter
+ *   Array containing ImageMagick options.
+ * @param $op
+ *   String with the operation: 'resize', 'crop', 'rotate'.
+ */
+function _image_imagemagick_alter_invoke(&$filter, $op) {
+  foreach (module_implements('imagemagick_alter') as $module) {
+    $function = $module . '_imagemagick_alter'; 
+    $function($filter, $op);
+  }
+}
+
+/**
+ * Resize an image to the given width and height.
  */
 function image_imagemagick_resize($source, $dest, $width, $height) {
-  $filter = ' -scale '. $width .'x'. $height .'! -filter QUADRATIC';
+  $filter = array('resize' => '-resize '. $width .'x'. $height .'!');
+  _image_imagemagick_alter_invoke($filter, 'resize');
   return _image_imagemagick_convert($source, $dest, $filter);
 }
 
 /**
- * Rotate an image
+ * Rotate an image.
  */
 function image_imagemagick_rotate($source, $dest, $degrees, $bg_color = 0x000000) {
-  $filter = ' -rotate '. escapeshellarg($degrees) .' -background #'. str_pad(dechex($bg_color), 6, 0);
+  $filter = array(
+    'rotate' => '-rotate '. (float) $degrees,
+    'background' => '-background #'. str_pad(dechex($bg_color), 6, 0),
+  );
+  _image_imagemagick_alter_invoke($filter, 'rotate');
   return _image_imagemagick_convert($source, $dest, $filter);
 }
 
 /**
- * Crop an image to the specified dimensions
+ * Crop an image to the specified dimensions.
  */
 function image_imagemagick_crop($source, $dest, $x, $y, $width, $height) {
-  $filter = ' -crop '. $width .'x'. $height .'+'. $x .'+'. $y;
+  $filter = array('crop' => '-crop '. $width .'x'. $height .'+'. $x .'+'. $y);
+  _image_imagemagick_alter_invoke($filter, 'crop');
   return _image_imagemagick_convert($source, $dest, $filter);
 }
 
 /**
- * Calls the convert executable with the specified filter
+ * Calls the convert executable with the specified filter.
  */
 function _image_imagemagick_convert($source, $dest, $filter) {
-  if (variable_get('image_imagemagick_option_strip', 0)) {
-    $filter .= ' -strip ';
-  }
-
   $command = implode(' ', array(
-    preg_replace("/[^A-Za-z0-9\!\.\-\+\040]/", '', $filter),
+    preg_replace("/[^A-Za-z0-9\!\.\-\+\040]/", '', implode(' ', $filter)),
     escapeshellarg($source),
     escapeshellarg($dest),
   ));
