private function _exec($program, $params, $passthru = false)
{
// Determine the path
$this->im_path = realpath($this->configuration['imagemagick_dir'] . $program);
// store the filename for this image
$filename = $this->imagick()->getImageFilename();
// check imagemagick is where we expect it
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']);
}
// save the filters that have already been applied
$this->imagick()->writeImage($filename);
$command = $this->im_path . " " . $params;
$code = 0;
$output = null;
//do the actual command
$passthru ? passthru($command) : exec($command, $output, $code);
// reload the imagemagick instance once the manual command is done
$this->image->imagick(new \Imagick($filename));
// check if it's successful
if ($code != 0) {
throw new \Exception("imagemagick failed to edit the image. Returned with {$code}.<br /><br />Command:\n <code>{$command}</code>");
}
return $output;
}