Index: image.imagemagick.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.imagemagick.inc,v
retrieving revision 1.3.2.3
diff -u -p -r1.3.2.3 image.imagemagick.inc
--- image.imagemagick.inc	20 Mar 2007 17:19:45 -0000	1.3.2.3
+++ image.imagemagick.inc	28 Mar 2007 18:01:14 -0000
@@ -12,23 +12,37 @@ function image_imagemagick_info() {
  * Validate and return toolkit specific settings
  */
 function image_imagemagick_settings() {
+  $form['#after_build'] = array('image_imagemagick_valid_file_after');
   $form['image_imagemagick_convert'] = array(
     '#type' => 'textfield',
     '#title' => t('Location of the "convert" binary'),
     '#default_value' => variable_get('image_imagemagick_convert', '/usr/bin/convert'),
     '#size' => 64,
     '#required' => TRUE,
-    '#validate' => array('image_imagemagick_valid_file' => array('image_imagemagick_convert')),
   );
   return $form;
 }
 
-function image_imagemagick_valid_file($formelement = NULL, $fieldname = NULL) {
-  $convert_path = $formelement['#value'];
+function image_imagemagick_valid_file_after($form, $form_element) {
+  if (image_imagemagick_check_path($form_element['image_imagemagick_convert'], 'image_imagemagick_convert')) {
+    _image_imagemagick_exec('-version', $output, $errors);
+    $form['image_imagemagick_version'] = array(
+      '#type' => 'item',
+      '#title' => t('Version'),
+      '#value' => $output,
+    );
+  }
+  return $form;
+}
 
-  if (!is_file($convert_path)) {
-    form_set_error($fieldname, t('%file does not exist.', array('%file' => $convert_path)));
+function image_imagemagick_check_path($path, $attach_error_to = FALSE) {
+  if (is_file($path)) {
+    return TRUE;
+  }
+  if ($attach_error_to) {
+    form_set_error($attach_error_to, t('The specified ImageMagic path %file does not exist.', array('%file' => $path)));
   }
+  return FALSE;
 }
 
 /**
@@ -59,47 +73,45 @@ function image_imagemagick_crop($source,
  * Calls the convert executable with the specified filter
  */
 function _image_imagemagick_convert($source, $dest, $filter) {
-  $convert_path = variable_get('image_imagemagick_convert', '/usr/bin/convert');
-  if (!file_exists($convert_path)) {
-    return FALSE;
-  }
-
-  if (strstr($_SERVER['SERVER_SOFTWARE'], 'Win32') || strstr($_SERVER['SERVER_SOFTWARE'], 'IIS')) {
-    // 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
-    // file paths don't have to be absolute.
-    $convert_path = 'start "window title" /D'. getcwd() .' /b '. escapeshellarg($convert_path);
-  }
-
   $command = implode(' ', array(
-    $convert_path,
     preg_replace("/[^A-Za-z0-9\!\.\-\+\040]/", '', $filter),
     escapeshellarg($source),
     escapeshellarg($dest),
   ));
 
-
   $status = _image_imagemagick_exec($command, $output, $error);
   if ($error) {
-    drupal_set_message("ImageMagick reported an error: $error");
-    #drupal_set_message("ImageMagick command: $command");
-    #drupal_set_message("ImageMagick output: $output");
+    drupal_set_message(t("ImageMagick reported an error: %error", array('%error' => $error)), 'error');
+    #drupal_set_message(t("ImageMagick command: %command", array('%command' => $command)));
+    #drupal_set_message(t("ImageMagick output: %output", array('%output' => $output)));
   }
-
   if ($status != 0) {
     return FALSE;
   }
   return file_exists($dest);
 }
 
-function _image_imagemagick_exec($command, &$output, &$errors) {
+function _image_imagemagick_exec($command_args, &$output, &$errors) {
+  $convert_path = variable_get('image_imagemagick_convert', '/usr/bin/convert');
+  if (!image_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');
+    return FALSE;
+  }
+
+  if (strstr($_SERVER['SERVER_SOFTWARE'], 'Win32') || strstr($_SERVER['SERVER_SOFTWARE'], 'IIS')) {
+    // 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
+    // file paths don't have to be absolute.
+    $convert_path = 'start "window title" /D'. getcwd() .' /b '. escapeshellarg($convert_path);
+  }
+  
   $descriptors = array(
     0 => array('pipe', 'r'), // stdin
     1 => array('pipe', 'w'), // stdout
     2 => array('pipe', 'w')  // stderr
   );
-  if ($h = proc_open($command, $descriptors, $pipes)) {
+  if ($h = proc_open($convert_path .' '. $command_args, $descriptors, $pipes)) {
     $output = fgets($pipes[1]);
     $errors = fgets($pipes[2]);
     fclose($pipes[0]);
