public function exec($program, $params, $passthru = false)
{
// Determine the path
$this->im_path = realpath($this->configuration['imagemagick_dir'] . $program);
if (!$this->im_path) {
$this->im_path = realpath($this->configuration['imagemagick_dir'] . $program . '.exe');
}
if (!$this->im_path) {
throw new \RuntimeException("imagemagick executables not found in " . $this->configuration['imagemagick_dir']);
}
$this->imagick()->writeImage();
$command = $this->im_path . " " . $params;
$this->debug("Running command: <code>{$command}</code>");
$code = 0;
$output = null;
$passthru ? passthru($command) : exec($command, $output, $code);
$this->imagick(new \Imagick($this->image()));
if ($code != 0) {
throw new \Exception("imagemagick failed to edit the image. Returned with {$code}.<br /><br />Command:\n <code>{$command}</code>");
}
return $output;
}