Index: imageapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi.module,v
retrieving revision 1.9
diff -u -p -r1.9 imageapi.module
--- imageapi.module	30 Mar 2008 23:25:10 -0000	1.9
+++ imageapi.module	13 Apr 2008 20:45:11 -0000
@@ -73,7 +73,7 @@ function imageapi_settings() {
       // The variable needs to be manually set. Otherwise, if a user has two 
       // toolkits and disables the selected one they won't be able to select the 
       // remaing toolkit.
-      variable_set('imageapi_toolkit', $toolkit);
+      variable_set('imageapi_image_toolkit', $toolkit);
       $form['imageapi_image_toolkit']['#value'] = t('The %toolkit module is the only enabled image toolkit. Drupal will use it for resizing, cropping and other image manipulations.', array('%toolkit' => $toolkits[$toolkit]['name']));
       return $form;
             
Index: imageapi_imagemagick.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi_imagemagick.module,v
retrieving revision 1.3
diff -u -p -r1.3 imageapi_imagemagick.module
--- imageapi_imagemagick.module	2 Apr 2008 07:57:29 -0000	1.3
+++ imageapi_imagemagick.module	13 Apr 2008 20:45:11 -0000
@@ -29,8 +29,7 @@ function imageapi_imagemagick_settings_f
     '#field_suffix' => '%',
     '#validate' => array('imageapi_imagemagick_quality_element_validate' => array()),
   );
-  $form['#after_build'] = array('_imageapi_imagemagick_build_version');
-  
+
   $form['imageapi_imagemagick_binary'] = array(
     '#type' => 'fieldset',
     '#title' => t('ImageMagick Binary'),
@@ -43,37 +42,32 @@ function imageapi_imagemagick_settings_f
     '#default_value' => variable_get('imageapi_imagemagick_convert', '/usr/bin/convert'),
     '#required' => TRUE,
     '#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>'),
-    '#validate' => array('_imageapi_imagemagick_checkpath' => array()),
   );
   $form['imageapi_imagemagick_binary']['imageapi_imagemagick_debugging'] = array(
     '#type' => 'checkbox',
     '#title' => t('Display debugging information'),
     '#default_value' => variable_get('imageapi_imagemagick_debugging', 0),
     '#description' => t('Checking this option will display the ImageMagick commands and ouput to users with the <em>administer site configuration</em> permission.'),
+    '#weight' => 2,
   );
+  $form['#after_build'] = array('_imageapi_imagemagick_build_version');
+
   return system_settings_form($form);
 }
 
 function _imageapi_imagemagick_build_version($form, $form_element) {
-  _imageapi_imagemagick_convert_exec('-version', $output, $errors);
-  $form['imageapi_imagemagick_binary']['version'] = array(
-    '#type' => 'item',
-    '#value' => '<pre>'. check_plain(trim($output)) .'</pre>',
-  );
-  return $form;
-}
-
-function _imageapi_imagemagick_validate_path($element) {
-  if (_imageapi_imagemagick_check_path($element['#value'])) {
-    return TRUE;
-  }
-  if ($open_basedir = ini_get('open_basedir')) {
-    form_set_error($element['#parents'][0], t("No file %file could be found. PHP's <a href='!open-basedir'>open_basedir</a> security resriction is set to %open-basedir, which may be interfearing with the attempts to locate ImageMagick.", array('%file' => $path, '%open-basedir' => $open_basedir, '!info-link' => url('http://php.net/features.safe-mode#ini.open-basedir') )));
+  $path = $form_element['imageapi_imagemagick_convert'];
+  if (_imageapi_imagemagick_check_path($path, 'imageapi_imagemagick_convert')) {
+    _imageapi_imagemagick_convert_exec('-version', $output, $errors, $path);
+    $form['imageapi_imagemagick_binary']['version'] = array(
+      '#type' => 'item',
+      '#title' => t('Version information'),
+      '#value' => '<pre>'. check_plain(trim($output)) .'</pre>',
+      '#description' => t('The ImageMagick <kbd>convert</kbd> binary was located and return this version information.'),
+      '#weight' => 1,
+    );
   }
-  else {
-    form_set_error($element['#parents'][0], t('The specified ImageMagick path %file does not exist.', array('%file' => $path)));
-  }
-  return FALSE;
+  return $form;
 }
 
 function imageapi_imagemagick_quality_element_validate($element) {  
@@ -98,8 +92,7 @@ function imageapi_imagemagick_image_clos
 
 function imageapi_imagemagick_image_crop(&$image, $x, $y, $width, $height) {
   $args = array('crop' => '-crop '. (int) $width .'x'. (int) $height .'+'. (int) $x .'+'. (int) $y .'!');
-  $args = _imageapi_imagemagick_alter_invoke('crop', $source, $args);
-  if (!_imageapi_imagemagick_convert($source, $dest, $args)) {
+  if (!_imageapi_imagemagick_convert($image->res, $image->res, $args)) {
     return FALSE;
   }
   return TRUE;
@@ -107,7 +100,6 @@ function imageapi_imagemagick_image_crop
 
 function imageapi_imagemagick_image_resize(&$image, $width, $height) {
   $args = array('resize' => '-resize '. (int) $width .'x'. (int) $height .'!');
-  $args = _imageapi_imagemagick_alter_invoke('resize', $source, $args);
   if (!_imageapi_imagemagick_convert($image->res, $image->res, $args)) {
     return FALSE;
   }
@@ -121,40 +113,15 @@ function imageapi_imagemagick_image_rota
     'rotate' => '-rotate '. (float) $degrees,
     'background' => '-background #'. str_pad(dechex($bg_color), 6, 0),
   );
-  $args = _imageapi_imagemagick_alter_invoke('rotate', $source, $args);
   return _imageapi_imagemagick_convert($image->res, $image->res, $args);
 } 
 
 function imageapi_imagemagick_image_desaturate(&$image) {
   $args = array('desaturate' => '-colorspace GRAY');
-  $args = _imageapi_imagemagick_alter_invoke('desaturate', $source, $args);
   return _imageapi_imagemagick_convert($image->res, $image->res, $args);
 }
 
 /**
- * Invoke hook_imagemagick_alter().
- *
- * Implementors of hook_imagemagick_alter() should accept three parameters: $op,
- * $filepath and &$args (passed by reference), which are described below.
- *
- * @param $op
- *   String with the operation: 'resize', 'crop', 'rotate'.
- * @param $filepath
- *   String containing the path to the image that is being processed.
- * @param $args
- *   Array containing ImageMagick options.
- * @return
- *   Array of modified arguments.
- */
-function _imageapi_imagemagick_alter_invoke($op, $filepath, $args) {
-  foreach (module_implements('imagemagick_alter') as $module) {
-    $function = $module .'_imagemagick_alter'; 
-    $function($op, $filepath, $args);
-  }
-  return $args;
-}
-
-/**
  * Calls the convert executable with the specified filter.
  */
 function _imageapi_imagemagick_convert($source, $dest, $args) {
@@ -171,14 +138,25 @@ function _imageapi_imagemagick_convert($
   return file_exists($dest);
 }
 
-function _imageapi_imagemagick_check_path($path) {
-  return is_file($path) && is_executable($path);
+function _imageapi_imagemagick_check_path($path, $attach_error_to = FALSE) {
+  if (is_file($path)) {
+    return TRUE;
+  }
+  if ($attach_error_to) {
+    if ($open_basedir = ini_get('open_basedir')) {
+      form_set_error($attach_error_to, t("No file %file could be found. PHP's <a href='!open-basedir'>open_basedir</a> security resriction is set to %open-basedir, which may be interfearing with the attempts to locate ImageMagick.", array('%file' => $path, '%open-basedir' => $open_basedir, '!info-link' => url('http://php.net/features.safe-mode#ini.open-basedir') )));
+    }
+    else {
+      form_set_error($attach_error_to, t('The specified ImageMagic path %file does not exist.', array('%file' => $path)));
+    }
+  }
+  return FALSE;
 }
 
-function _imageapi_imagemagick_convert_exec($command_args, &$output, &$errors) {
-  $convert_path = variable_get('imageapi_imagemagick_convert', '/usr/bin/convert');
+function _imageapi_imagemagick_convert_exec($command_args, &$output, &$errors, $convert_path = '') {
+  $convert_path = !empty($convert_path) ? $convert_path : variable_get('imageapi_imagemagick_convert', '/usr/bin/convert');
   if (!_imageapi_imagemagick_check_path($convert_path)) {
-    drupal_set_message(t("ImageMagick could not be found. The admin will need to set the path on the <a href='@image-toolkit-settings'>image toolkit page</a>.", array('@image-toolkit-settings' => url('admin/settings/image-toolkit'))), 'error');
+    drupal_set_message(t("ImageMagick could not be found. The admin will need to set the path on the <a href='@image-toolkit-settings'>image toolkit page</a>.", array('@image-toolkit-settings' => url('admin/settings/imageapi/config/imageapi_imagemagick'))), 'error');
     return FALSE;
   }
 
