You are here

function _image_imagemagick_convert_exec in Image 6

Same name and namespace in other branches
  1. 5.2 image.imagemagick.inc \_image_imagemagick_convert_exec()
  2. 5 image.imagemagick.inc \_image_imagemagick_convert_exec()
  3. 7 image.imagemagick.inc \_image_imagemagick_convert_exec()
2 calls to _image_imagemagick_convert_exec()
_image_imagemagick_build_version in ./image.imagemagick.inc
_image_imagemagick_convert in ./image.imagemagick.inc
Calls the convert executable with the specified filter.

File

./image.imagemagick.inc, line 138

Code

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)) {
    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' . escapeshellarg(getcwd()) . ' /B ' . escapeshellarg($convert_path);
  }
  $descriptors = array(
    0 => array(
      'pipe',
      'r',
    ),
    // stdin
    1 => array(
      'pipe',
      'w',
    ),
    // stdout
    2 => array(
      'pipe',
      'w',
    ),
  );
  if ($h = proc_open($convert_path . ' ' . $command_args, $descriptors, $pipes)) {
    $output = '';
    while (!feof($pipes[1])) {
      $output .= fgets($pipes[1]);
    }
    $errors = '';
    while (!feof($pipes[2])) {
      $errors .= fgets($pipes[2]);
    }

    // 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 output: @output', array(
        '@output' => $output,
      )));
    }
    if ($errors) {
      drupal_set_message(t('ImageMagick reported an error: %error.', array(
        '%error' => $errors,
      )), 'error');
    }
    fclose($pipes[0]);
    fclose($pipes[1]);
    fclose($pipes[2]);
    return proc_close($h);
  }
  return FALSE;
}