You are here

function _imagemagick_check_path in ImageMagick 7

Verifies file path of ImageMagick convert binary by checking its version.

Parameters

$file: The user-submitted file path to the convert binary.

Return value

An associative array containing:

  • output: The shell output of 'convert -version', if any.
  • errors: A list of error messages indicating whether ImageMagick could not be found or executed.
2 calls to _imagemagick_check_path()
imagemagick_element_validate_path in ./imagemagick.module
Form element validation handler for convert executable path setting.
_imagemagick_build_version in ./imagemagick.module
#after_build callback to output ImageMagick version or any errors in image toolkit settings form.

File

./imagemagick.module, line 146
Provides ImageMagick integration.

Code

function _imagemagick_check_path($file) {
  $status = array(
    'output' => '',
    'errors' => array(),
  );

  // If only the name of the executable is given, we only check whether it is in
  // the path and can be invoked.
  if ($file != 'convert' && $file != 'gm') {

    // Check whether the given file exists.
    if (!is_file($file)) {
      $status['errors'][] = t('The specified ImageMagick file path %file does not exist.', array(
        '%file' => $file,
      ));
    }
    elseif (!is_executable($file)) {
      $status['errors'][] = t('The specified ImageMagick file path %file is not executable.', array(
        '%file' => $file,
      ));
    }
  }

  // In case of errors, check for open_basedir restrictions.
  if ($status['errors'] && ($open_basedir = ini_get('open_basedir'))) {
    $status['errors'][] = t('The PHP <a href="@php-url">open_basedir</a> security restriction is set to %open-basedir, which may prevent to locate ImageMagick.', array(
      '%open-basedir' => $open_basedir,
      '@php-url' => 'http://php.net/manual/en/ini.core.php#ini.open-basedir',
    ));
  }

  // Unless we had errors so far, try to invoke convert.
  if (!$status['errors']) {
    $result = _imagemagick_convert_exec('-version', $status['output'], $error, $file);

    // _imagemagick_convert_exec() triggers a user error upon failure, but
    // during form validation all errors need to be reported.
    if ($error !== '') {

      // $error normally needs check_plain(), but file system errors on Windows
      // use a unknown encoding. check_plain() would eliminate the entire string.
      $status['errors'][] = $error;
    }
  }
  return $status;
}