Index: imageapi/imageapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi.module,v
retrieving revision 1.23.2.3
diff -u -p -r1.23.2.3 imageapi.module
--- imageapi/imageapi.module	18 Mar 2009 08:35:59 -0000	1.23.2.3
+++ imageapi/imageapi.module	19 Apr 2009 22:54:22 -0000
@@ -362,21 +362,15 @@ function imageapi_image_desaturate(&$ima
  *   An image object or FALSE if there was a problem loading the file. The
  *   image object has the following properties:
  *    - 'source' - The original file path.
- *    - 'info' - The array of information returned by image_get_info()
+ *    - 'info' - The array of information returned by imageapi_image_get_info()
  *    - 'toolkit' - The name of the image toolkit requested when the image was
  *      loaded.
  *   Image tookits may add additional properties. The caller is advised not to
  *   monkey about with them.
  */
 function imageapi_image_open($file, $toolkit = FALSE) {
-  if (!$toolkit) {
-    $toolkit = imageapi_default_toolkit();
-  }
-  if ($toolkit) {
-    $image = new stdClass();
-    $image->source = $file;
-    $image->info = image_get_info($file);
-    $image->toolkit = $toolkit;
+  $image = imageapi_image_get_info($file, $toolkit, TRUE);
+  if ($image->toolkit) {
     if (imageapi_toolkit_invoke('open', $image)) {
       return $image;
     }
@@ -403,7 +397,7 @@ function imageapi_image_close($image, $d
   if ($return = imageapi_toolkit_invoke('close', $image, array($destination))) {
     // Clear the cached file size and refresh the image information.
     clearstatcache();
-    $image->info = image_get_info($destination);
+    $image->info = imageapi_image_get_info($destination);
 
     if (@chmod($destination, 0664)) {
       return $return;
@@ -461,3 +455,46 @@ function imageapi_hex2rgba($hex) {
   return array($r, $g, $b, $a);
 }
 
+/**
+ * Get details about an image.
+ *
+ * Drupal supports GIF, JPG and PNG file formats, and may support 
+ * additional formats if toolkits such as Imagemagick are enabled.
+ * 
+ * @param $file
+ *   Path to an image file.
+ * @param $toolkit
+ *   An optional, image toolkit name to override the default.
+ * @param $return_image_object
+ *   Whether an image object should be returned, or just the info.
+ * @return
+ *   FALSE, if the file could not be found or is not an image. Otherwise, a
+ *   keyed array containing information about the image:
+ *    'width'     - Width in pixels.
+ *    'height'    - Height in pixels.
+ *    'extension' - Commonly used file extension for the image.
+ *    'mime_type' - MIME type e.g. 'image/jpeg', 'image/gif', 'image/png'.
+ *    'file_size' - File size in bytes.
+ */
+function imageapi_image_get_info($file, $tookit = FALSE, $return_image_object = FALSE) {
+  if (!$toolkit) {
+    $toolkit = imageapi_default_toolkit();
+  }
+  if ($toolkit) {
+    $image = new stdClass();
+    $image->source = $file;
+    $image->toolkit = $toolkit;
+  } 
+  if (is_file($file)) {
+    $image->info = imageapi_toolkit_invoke('get_info', $image);
+  }
+  else {
+    $image->info = FALSE;
+  }
+  if ($return_image_object) {
+    return $image;
+  }
+  else {
+    return $image->info;
+  }
+}
Index: imageapi/imageapi_gd.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi_gd.module,v
retrieving revision 1.13.2.5
diff -u -p -r1.13.2.5 imageapi_gd.module
--- imageapi/imageapi_gd.module	18 Mar 2009 08:05:39 -0000	1.13.2.5
+++ imageapi/imageapi_gd.module	19 Apr 2009 22:54:22 -0000
@@ -406,3 +406,23 @@ function imageapi_gd_unsharp_mask($img, 
 
   return $img;
 }
+
+/**
+ * Get details about an image.
+ *
+ * GD only supports GIF, JPG and PNG file formats.
+ *
+ * @param $image
+ *   An image object 
+ * @return
+ *   FALSE, if the file could not be found or is not an image. Otherwise, a
+ *   keyed array containing information about the image:
+ *    'width'     - Width in pixels.
+ *    'height'    - Height in pixels.
+ *    'extension' - Commonly used file extension for the image.
+ *    'mime_type' - MIME type ('image/jpeg', 'image/gif', 'image/png').
+ *    'file_size' - File size in bytes.
+ */
+function imageapi_gd_image_get_info($image) {
+  return image_get_info($image->source);
+}
Index: imageapi/imageapi_imagemagick.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imageapi/imageapi_imagemagick.module,v
retrieving revision 1.17.2.3
diff -u -p -r1.17.2.3 imageapi_imagemagick.module
--- imageapi/imageapi_imagemagick.module	18 Mar 2009 07:59:56 -0000	1.17.2.3
+++ imageapi/imageapi_imagemagick.module	19 Apr 2009 22:54:22 -0000
@@ -31,9 +31,9 @@ function imageapi_imagemagick_settings_f
 
   $form['imageapi_imagemagick_binary'] = array(
     '#type' => 'fieldset',
-    '#title' => t('ImageMagick Binary'),
+    '#title' => t('ImageMagick Binaries'),
     '#collapsible' => FALSE,
-    '#description' => t('ImageMagick is a standalone program used to manipulate images. To use it, it must be installed on your server and you need to know where it is located. If you are unsure of the exact path consult your ISP or server administrator.'),
+    '#description' => t('ImageMagick is a collection of  standalone programs used to manipulate images. To use it, it must be installed on your server and you need to know where the programs are located. If you are unsure of the exact paths consult your ISP or server administrator.'),
   );
 
   $form['imageapi_imagemagick_binary']['version'] = array('#weight' => -1);
@@ -44,10 +44,19 @@ function imageapi_imagemagick_settings_f
     '#title' => t('Path to the "convert" binary'),
     '#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>'),
+    '#description' => t('Specify the complete path to the ImageMagick <kbd>convert</kbd> binary. For example: <kbd>/usr/bin/convert</kbd> or <kbd>C:\Program Files\ImageMagick-6.3.4-Q16\convert.exe</kbd>'),
     '#element_validate' => array('imageapi_imagemagick_validate_path'),
   );
 
+  $form['imageapi_imagemagick_binary']['imageapi_imagemagick_identify'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to the "identify" binary'),
+    '#default_value' => variable_get('imageapi_imagemagick_identify', '/usr/bin/identify'),
+    '#required' => TRUE,
+    '#description' => t('Specify the complete path to the ImageMagick <kbd>identify</kbd> binary. This will usually be in the same place as the <kbd>convert</kbd> binary.'),
+    '#element_validate' => array('imageapi_imagemagick_validate_path'),
+   );
+
   $form['imageapi_imagemagick_binary']['imageapi_imagemagick_debugging'] = array(
     '#type' => 'checkbox',
     '#title' => t('Display debugging information'),
@@ -142,14 +151,51 @@ function imageapi_imagemagick_image_desa
 }
 
 /**
+ * Get details about an image.
+ *
+ * Imagemagick supports a number of file formats.
+ *
+ * @param $image
+ *   An image object.
+ * @return
+ *   FALSE, if the file could not be found or is not an image. Otherwise, a
+ *   keyed array containing information about the image:
+ *    'width'     - Width in pixels.
+ *    'height'    - Height in pixels.
+ *    'extension' - Commonly used file extension for the image.
+ *    'mime_type' - MIME type, e.g. 'image/jpeg', 'image/gif', 'image/png'.
+ *    'file_size' - File size in bytes.
+ */
+function imageapi_imagemagick_image_get_info($image) {
+  $info = FALSE;
+  _imageapi_imagemagick_identify_exec("-format \"%w %h %m %b\" " . escapeshellarg($image->source), $output, $errors);
+  $results = explode(' ', $output);
+  if (count($results)) {
+    $extension = strtolower($results[2]); 
+    $info = array('width' => $results[0],
+                  'height' => $results[1],
+                  'extension' => $extension,
+                  'file_size' => $results[3],
+                  'mime_type' => file_get_mimetype($image->source));
+  }
+  return $info;
+}
+
+/**
  * Calls the convert executable with the specified filter.
  */
 function _imageapi_imagemagick_convert($source, $dest, $args) {
   $args['quality'] = '-quality '. escapeshellarg(variable_get('imageapi_imagemagick_quality', 75));
+
+  // When an image contains more than one layer, ImageMagick normally converts
+  // to more than one image. But we don't want this, so we pass the -append
+  // argument. This has no effect on single-layered images.
+  $args['append'] = '-append';
+
   // To make use of ImageMagick 6's parenthetical command grouping we need to make
   // the $source image the first parameter and $dest the last.
   // See http://www.imagemagick.org/Usage/basics/#cmdline for more info.
-  $command = escapeshellarg($source) .' '. implode(' ', $args) .' '. escapeshellarg($dest);
+  $command = escapeshellarg($source . '[0]') .' '. implode(' ', $args) .' '. escapeshellarg($dest);
 
   if (0 != _imageapi_imagemagick_convert_exec($command, $output, $errors)) {
     return FALSE;
@@ -173,7 +219,16 @@ function _imageapi_imagemagick_check_pat
 
 function _imageapi_imagemagick_convert_exec($command_args, &$output, &$errors) {
   $convert_path = variable_get('imageapi_imagemagick_convert', '/usr/bin/convert');
-  if ($errors = _imageapi_imagemagick_check_path($convert_path)) {
+  return _imageapi_imagemagick_exec($convert_path, $command_args, $output, $errors);
+}
+
+function _imageapi_imagemagick_identify_exec($command_args, &$output, &$errors) {
+  $identify_path = variable_get('imageapi_imagemagick_identify', '/usr/bin/identify');
+  return _imageapi_imagemagick_exec($identify_path, $command_args, $output, $errors);
+}
+
+function _imageapi_imagemagick_exec($command_path, $command_args, &$output, &$errors) {
+  if ($errors = _imageapi_imagemagick_check_path($command_path)) {
     watchdog('imageapi imagemagick', '!errors', array('!errors' => implode('<br />', $errors)), WATCHDOG_ERROR);
     return FALSE;
   }
@@ -183,7 +238,7 @@ function _imageapi_imagemagick_convert_e
     // 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'. escapeshellarg(getcwd()) .' /B '. escapeshellarg($convert_path);
+    $command_path = 'start "window title" /D'. escapeshellarg(getcwd()) .' /B '. escapeshellarg($command_path);
   }
 
   $descriptors = array(
@@ -191,7 +246,7 @@ function _imageapi_imagemagick_convert_e
     1 => array('pipe', 'w'), // stdout
     2 => array('pipe', 'w')  // stderr
   );
-  if ($h = proc_open($convert_path .' '. $command_args, $descriptors, $pipes)) {
+  if ($h = proc_open($command_path .' '. $command_args, $descriptors, $pipes)) {
     $output = '';
     while (!feof($pipes[1])) {
       $output .= fgets($pipes[1]);
@@ -204,7 +259,7 @@ function _imageapi_imagemagick_convert_e
 
     // Display debugging information to authorized users.
     if (variable_get('imageapi_imagemagick_debugging', FALSE) && user_access('administer site configuration')) {
-      drupal_set_message(t('ImageMagick command: @command', array('@command' => $convert_path .' '. $command_args)));
+      drupal_set_message(t('ImageMagick command: @command', array('@command' => $command_path .' '. $command_args)));
       drupal_set_message(t('ImageMagick output: @output', array('@output' => $output)));
     }
 
