Index: image.imagemagick.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.imagemagick.inc,v
retrieving revision 1.3.2.9
diff -u -p -u -r1.3.2.9 image.imagemagick.inc
--- image.imagemagick.inc	10 Jul 2007 00:56:19 -0000	1.3.2.9
+++ image.imagemagick.inc	16 Aug 2007 20:17:04 -0000
@@ -28,19 +28,6 @@ function image_imagemagick_settings() {
     '#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,62 @@ function _image_imagemagick_check_path($
 }
 
 /**
- * Resize an image to the given width and height
+ * Invoke hook_imagemagick_alter().
+ *
+ * Implementors of hook_imagemagick_alter() should accept two parameters: $op
+ * and $args, which are described below.   
+ *
+ * @param $op
+ *   String with the operation: 'resize', 'crop', 'rotate'.
+ * @param $args
+ *   Array containing ImageMagick options.
+ * @return
+ *   Array of modified arguments.
+ */
+function _image_imagemagick_alter_invoke($op, $args) {
+  foreach (module_implements('imagemagick_alter') as $module) {
+    $function = $module .'_imagemagick_alter'; 
+    $function($op, $args);
+  }
+  return $args;
+}
+
+/**
+ * Resize an image to the given width and height.
  */
 function image_imagemagick_resize($source, $dest, $width, $height) {
-  $filter = ' -scale '. $width .'x'. $height .'! -filter QUADRATIC';
-  return _image_imagemagick_convert($source, $dest, $filter);
+  $args = array('resize' => '-resize '. $width .'x'. $height .'!');
+  $args = _image_imagemagick_alter_invoke('resize', $args);
+  return _image_imagemagick_convert($source, $dest, $args);
 }
 
 /**
- * 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);
-  return _image_imagemagick_convert($source, $dest, $filter);
+  $args = array(
+    'rotate' => '-rotate '. (float) $degrees,
+    'background' => '-background #'. str_pad(dechex($bg_color), 6, 0),
+  );
+  $args = _image_imagemagick_alter_invoke('rotate', $args);
+  return _image_imagemagick_convert($source, $dest, $args);
 }
 
 /**
- * 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;
-  return _image_imagemagick_convert($source, $dest, $filter);
+  $args = array('crop' => '-crop '. $width .'x'. $height .'+'. $x .'+'. $y);
+  $args = _image_imagemagick_alter_invoke('crop', $args);
+  return _image_imagemagick_convert($source, $dest, $args);
 }
 
 /**
- * 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 ';
-  }
-
+function _image_imagemagick_convert($source, $dest, $args) {
   $command = implode(' ', array(
-    preg_replace("/[^A-Za-z0-9\!\.\-\+\040]/", '', $filter),
+    preg_replace("/[^A-Za-z0-9\!\.\-\+\_\/\040]/", '', implode(' ', $args)),
     escapeshellarg($source),
     escapeshellarg($dest),
   ));
@@ -126,9 +136,9 @@ function _image_imagemagick_convert_exec
   }
 
   if (strstr($_SERVER['SERVER_SOFTWARE'], 'Win32') || strstr($_SERVER['SERVER_SOFTWARE'], 'IIS')) {
-    // use window's start command to avoid the "black window" from showing up:
+    // Use Window's start command to avoid the "black window" from showing up:
     // http://us3.php.net/manual/en/function.exec.php#56599
-    // use /D to run the command from PHP's current working directory so the
+    // Use /D to run the command from PHP's current working directory so the
     // file paths don't have to be absolute.
     $convert_path = 'start "window title" /D'. getcwd() .' /b '. escapeshellarg($convert_path);
   }

