--- ../../../../drupal-6.10-unpatched/sites/all/modules/image/image.imagemagick.inc 2008-12-27 01:58:41.000000000 -0500
+++ image/image.imagemagick.inc 2009-03-13 02:19:16.000000000 -0400
@@ -18,15 +18,22 @@ function image_imagemagick_settings() {
'#type' => 'fieldset',
'#title' => t('ImageMagick binary'),
'#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 it is located. If you are unsure of the exact path consult your ISP or server administrator.'),
);
$form['imagemagick_binary']['image_imagemagick_convert'] = array(
'#type' => 'textfield',
'#title' => t('Path to the "convert" binary'),
'#default_value' => variable_get('image_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.'),
);
+ $form['imagemagick_binary']['image_imagemagick_identify'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Path to the "identify" binary'),
+ '#default_value' => variable_get('image_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['imagemagick_binary']['image_imagemagick_debugging'] = array(
'#type' => 'checkbox',
'#title' => t('Display debugging information'),
@@ -89,6 +96,60 @@ function _image_imagemagick_alter_invoke
return $args;
}
+function _image_imagemagick_mime_type($file, $type) {
+ static $finfo = null;
+ if (function_exists('finfo_open')) {
+ if (is_null($finfo))
+ $finfo = finfo_open(FILEINFO_MIME);
+ return finfo_file($finfo, $file);
+ }
+ elseif (function_exists('mime_content_type'))
+ return mime_content_type($file);
+ else {
+ switch ($type) {
+ case 'pdf':
+ return 'application/pdf';
+ case 'ai':
+ case 'ps':
+ case 'eps':
+ return 'application/postscript';
+ default:
+ return "image/$type";
+ }
+ }
+}
+
+/**
+ * Return info about the given image file.
+ */
+function image_imagemagick_get_info($file) {
+ static $cache = array();
+ if (!isset($cache[$file])) {
+ _image_imagemagick_identify_exec("-format \"%w %h %m\" " . escapeshellarg($file), $output, $errors);
+ $results = explode(' ', $output);
+ if (count($results)) {
+ $type = strtolower($results[2]);
+ $details = array(
+ 'width' => $results[0],
+ 'height' => $results[1],
+ 'extension' => $type,
+ 'mime_type' => _image_imagemagick_mime_type($file, $type),
+ );
+ $cache[$file] = $details;
+ }
+ else
+ $cache[$file] = FALSE;
+ }
+ return $cache[$file];
+}
+
+/**
+ * Convert an image from one type to another (based on file extension)
+ */
+function image_imagemagick_convert($source, $dest) {
+ return _image_imagemagick_convert($source, $dest, array());
+}
+
/**
* Resize an image to the given width and height.
*/
@@ -123,6 +184,11 @@ function image_imagemagick_crop($source,
* Calls the convert executable with the specified filter.
*/
function _image_imagemagick_convert($source, $dest, $args) {
+ // 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';
+
$command = implode(' ', array(
preg_replace("/[^A-Za-z0-9\!\.\-\+\_\/\040]/", '', implode(' ', $args)),
escapeshellarg($source),
@@ -137,7 +203,16 @@ function _image_imagemagick_convert($sou
function _image_imagemagick_convert_exec($command_args, &$output, &$errors) {
$convert_path = variable_get('image_imagemagick_convert', '/usr/bin/convert');
- if (!_image_imagemagick_check_path($convert_path)) {
+ return _image_imagemagick_exec($convert_path, $command_args, $output, $errors);
+}
+
+function _image_imagemagick_identify_exec($command_args, &$output, &$errors) {
+ $identify_path = variable_get('image_imagemagick_identify', '/usr/bin/identify');
+ return _image_imagemagick_exec($identify_path, $command_args, $output, $errors);
+}
+
+function _image_imagemagick_exec($command_path, $command_args, &$output, &$errors) {
+ if (!_image_imagemagick_check_path($command_path)) {
drupal_set_message(t("ImageMagick could not be found. The admin will need to set the path on the image toolkit page.", array('@image-toolkit-settings' => url('admin/settings/image-toolkit'))), 'error');
return FALSE;
}
@@ -147,7 +222,7 @@ function _image_imagemagick_convert_exec
// 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(
@@ -155,7 +230,7 @@ function _image_imagemagick_convert_exec
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]);
@@ -168,7 +243,7 @@ function _image_imagemagick_convert_exec
// Display debugging information to authorized users.
if (variable_get('image_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)));
}