--- imageapi_imagemagick.module 2010-11-30 20:15:33.000000000 +0000
+++ imageapi_imagemagick.module 2010-12-04 17:37:01.000000000 +0000
@@ -47,6 +47,14 @@
'#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'),
'#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 ImageMagic identify binary. For example: /usr/bin/identify or C:\Program Files\ImageMagick-6.3.4-Q16\identify.exe'),
+ '#element_validate' => array('imageapi_imagemagick_validate_path'),
+ );
$form['imageapi_imagemagick_binary']['imageapi_imagemagick_debugging'] = array(
'#type' => 'checkbox',
'#title' => t('Display debugging information'),
@@ -83,9 +91,8 @@
}
function imageapi_imagemagick_validate_path($element) {
- if ($element['#post'] == 'imageapi_imagemagick' && $errors = _imageapi_imagemagick_check_path($element['#value'])) {
+ if ($errors = _imageapi_imagemagick_check_path($element['#value'])) {
form_set_error($element['#parents'][0], implode('
', $errors));
- //form_set_value($element['#parents'][0], variable_get('imageapi_imagemagick_convert', '/usr/bin/convert'));
return FALSE;
}
return TRUE;
@@ -97,13 +104,31 @@
}
}
+
+function image_imageapi_imagemagick_get_info(stdClass $image) {
+ $details = FALSE;
+ if (0 == _imageapi_imagemagick_identify_exec('-format "%w|%h|%C" '.drupal_realpath($image->source), $output, $errors)) {
+ $data = explode('|', $output);
+ $extensions = array('GIF' => 'gif', 'JPEG' => 'jpg', 'PNG' => 'png');
+ $mimetypes = array('GIF' => 'image/gif', 'JPEG' => 'image/jpeg', 'PNG' => 'image/png');
+
+ $details = array(
+ 'width' => $data[0],
+ 'height' => $data[1],
+ 'extension' => isset($extensions[$data[2]]) ? $extensions[$data[2]] : '',
+ 'mime_type' => isset($mimetypes[$data[2]]) ? $mimetypes[$data[2]] : '',
+ );
+ }
+ return $details;
+}
+
function image_imageapi_imagemagick_load(stdClass $image) {
$image->ops = array();
return $image;
}
function image_imageapi_imagemagick_save(stdClass $image, $destination) {
- return _imageapi_imagemagick_convert($image->source, $destination, $image->ops);
+ return _imageapi_imagemagick_convert(drupal_realpath($image->source), drupal_realpath($destination), $image->ops);
}
function image_imageapi_imagemagick_crop(stdClass $image, $x, $y, $width, $height) {
@@ -177,9 +202,8 @@
return $errors;
}
-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)) {
+function _imageapi_imagemagick_exec($path, $command_args, &$output, &$errors) {
+ if ($errors = _imageapi_imagemagick_check_path($path)) {
watchdog('imageapi imagemagick', '!errors', array('!errors' => implode('
', $errors)), WATCHDOG_ERROR);
return FALSE;
}
@@ -193,7 +217,7 @@
// 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($drupal_path) .' /B '. escapeshellarg($convert_path);
+ $path = 'start "window title" /D'. escapeshellarg($drupal_path) .' /B '. escapeshellarg($path);
}
$descriptors = array(
@@ -201,7 +225,7 @@
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w') // stderr
);
- if ($h = proc_open($convert_path .' '. $command_args, $descriptors, $pipes, $drupal_path)) {
+ if ($h = proc_open($path .' '. $command_args, $descriptors, $pipes, $drupal_path)) {
$output = '';
while (!feof($pipes[1])) {
$output .= fgets($pipes[1]);
@@ -219,7 +243,7 @@
// 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' => $path .' '. $command_args)));
drupal_set_message(t('ImageMagick output: @output', array('@output' => $output)));
}
@@ -242,3 +266,14 @@
}
return FALSE;
}
+
+function _imageapi_imagemagick_convert_exec($command_args, &$output, &$errors) {
+ $path = variable_get('imageapi_imagemagick_convert', '/usr/bin/convert');
+ return _imageapi_imagemagick_exec($path, $command_args, $output, $errors);
+}
+
+function _imageapi_imagemagick_identify_exec($command_args, &$output, &$errors) {
+ $path = variable_get('imageapi_imagemagick_identify', '/usr/bin/identify');
+ return _imageapi_imagemagick_exec($path, $command_args, $output, $errors);
+}
+