Instafilter\Image::exec PHP Method

exec() public method

Executes the specified imagemagick executable and returns the output.
public exec ( string $program, string $params, boolean $passthru = false ) : mixed
$program string The name of the executable.
$params string The parameters of the executable.
$passthru boolean Returns the output if false or pass it to browser.
return mixed Either returns the output or returns nothing.
    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;
    }