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 1 Apr 2009 22:52:42 -0000
@@ -461,3 +461,29 @@ function imageapi_hex2rgba($hex) {
return array($r, $g, $b, $a);
}
+/**
+ * Get details about an image.
+ *
+ * Drupal only supports GIF, JPG and PNG file formats.
+ *
+ * @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.
+ */
+// Should this function exist? Would it not be better to call this during the
+// imageapi_image_open() function?
+function imageapi_image_get_info($image) {
+ return imageapi_toolkit_invoke('get_info', $image);
+}
+
+function imageapi_get_info($file) {
+ $image = imageapi_image_open($file);
+ $info = imageapi_image_get_info($image);
+ imageapi_image_close($image);
+ return $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 1 Apr 2009 22:52:42 -0000
@@ -406,3 +406,39 @@ function imageapi_gd_unsharp_mask($img,
return $img;
}
+
+/**
+ * Get details about an image.
+ *
+ * GD only supports GIF, JPG and PNG file formats.
+ *
+ * @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) {
+ if (!is_file($image->source)) {
+ return FALSE;
+ }
+
+ $details = FALSE;
+ $data = @getimagesize($image->source);
+ $file_size = @filesize($image->source);
+
+ if (isset($data) && is_array($data)) {
+ $extensions = array('1' => 'gif', '2' => 'jpg', '3' => 'png');
+ $extension = array_key_exists($data[2], $extensions) ? $extensions[$data[2]] : '';
+ $details = array('width' => $data[0],
+ 'height' => $data[1],
+ 'extension' => $extension,
+ 'file_size' => $file_size,
+ 'mime_type' => $data['mime']);
+ }
+
+ return $details;
+}
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 1 Apr 2009 22:52:43 -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,18 @@ 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 convert binary. For example: /usr/bin/convert or C:\Program Files\ImageMagick-6.3.4-Q16\convert.exe'),
+ '#description' => t('Specify the complete path to the ImageMagick convert binary. For example: /usr/bin/convert or C:\Program Files\ImageMagick-6.3.4-Q16\convert.exe'),
'#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 identify binary. This will usually be in the same place as the convert binary.'),
+ );
+
$form['imageapi_imagemagick_binary']['imageapi_imagemagick_debugging'] = array(
'#type' => 'checkbox',
'#title' => t('Display debugging information'),
@@ -142,14 +150,56 @@ function imageapi_imagemagick_image_desa
}
/**
+ * Get details about an image.
+ *
+ * Imagemagick supports a number of file formats.
+ *
+ * @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_imagemagick_image_get_info($image) {
+ static $cache = array();
+ if (!isset($cache[$image->source])) {
+ _imageapi_imagemagick_identify_exec("-format \"%w %h %m\" " . escapeshellarg($image->source), $output, $errors);
+ $results = explode(' ', $output);
+ if (count($results)) {
+ $type = strtolower($results[2]); // Not used at present
+ $details = array(
+ 'width' => $results[0],
+ 'height' => $results[1],
+ 'extension' => $type,
+ 'mime_type' => file_get_mimetype($image->source),
+ );
+ $cache[$image->source] = $details;
+ }
+ else {
+ $cache[$image->source] = FALSE;
+ }
+ }
+ return $cache[$image->source];
+}
+
+/**
* 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';
+
// 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 +223,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('
', $errors)), WATCHDOG_ERROR);
return FALSE;
}
@@ -183,7 +242,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 +250,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 +263,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)));
}