public function ImagemagickToolkit::checkPath in ImageMagick 8
Same name and namespace in other branches
- 8.2 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::checkPath()
Verifies file path of the executable binary by checking its version.
Parameters
string $path: The user-submitted file path to the convert binary.
string $package: (optional) The graphics package to use.
Return value
array An associative array containing:
- output: The shell output of 'convert -version', if any.
- errors: A list of error messages indicating if the executable could not be found or executed.
3 calls to ImagemagickToolkit::checkPath()
- ImagemagickToolkit::buildConfigurationForm in src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php - Form constructor.
- ImagemagickToolkit::getRequirements in src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php - Gets toolkit requirements in a format suitable for hook_requirements().
- ImagemagickToolkit::validateConfigurationForm in src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php - Form validation handler.
File
- src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php, line 442
Class
- ImagemagickToolkit
- Provides ImageMagick integration toolkit for image manipulation.
Namespace
Drupal\imagemagick\Plugin\ImageToolkitCode
public function checkPath($path, $package = NULL) {
$status = [
'output' => '',
'errors' => [],
];
// Execute gm or convert based on settings.
$package = $package ?: $this
->getPackage();
$binary = $package === 'imagemagick' ? 'convert' : 'gm';
$executable = $this
->getExecutable($binary, $path);
// If a path is given, we check whether the binary exists and can be
// invoked.
if (!empty($path)) {
// Check whether the given file exists.
if (!is_file($executable)) {
$status['errors'][] = $this
->t('The @suite executable %file does not exist.', [
'@suite' => $this
->getPackageLabel($package),
'%file' => $executable,
]);
}
elseif (!is_executable($executable)) {
$status['errors'][] = $this
->t('The @suite file %file is not executable.', [
'@suite' => $this
->getPackageLabel($package),
'%file' => $executable,
]);
}
}
// In case of errors, check for open_basedir restrictions.
if ($status['errors'] && ($open_basedir = ini_get('open_basedir'))) {
$status['errors'][] = $this
->t('The PHP <a href=":php-url">open_basedir</a> security restriction is set to %open-basedir, which may prevent to locate the @suite executable.', [
'@suite' => $this
->getPackageLabel($package),
'%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']) {
$error = NULL;
$this
->runOsShell($executable, '-version', $package, $status['output'], $error);
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;
}