%s", $scanimage, escapeshellarg($outfile)); $this->execute($cmd); } public function convertPNMtoPNG($infile, $outfile) { $pnmtopng = '/usr/bin/pnmtopng'; if (!file_exists($pnmtopng)) throw new Exception("Package netpbm not installed"); if (!is_executable($pnmtopng)) throw new Exception("$pnmtopng not executable"); $cmd = sprintf("cat %s | %s > %s", escapeshellarg($infile), $pnmtopng, escapeshellarg($outfile)); $this->execute($cmd); } public function rotatePNM($file, $direction) { $convert = '/usr/bin/convert'; if (!file_exists($convert)) throw new Exception("Package imagemagick not installed"); if (!is_executable($convert)) throw new Exception("$scanimage not executable"); switch (intval($direction)) { case static::RIGHT: $degrees = 90; break; case static::FLIP: $degrees = 180; break; case static::LEFT: $degrees = 270; break; default: throw new Exception("Invalid rotation command"); } $cmd = sprintf("convert -rotate %d %s %s && mv -f %s %s", $degrees, escapeshellarg($file), escapeshellarg($file.'.pnm'), escapeshellarg($file.'.pnm'), escapeshellarg($file)); $this->execute($cmd); } public function convertPNMtoPDF($infile, $outfile) { $pnmtops = '/usr/bin/pnmtops'; $pstopdf = '/usr/bin/ps2pdf'; if (!file_exists($pnmtops)) throw new Exception("Package netpbm not installed"); if (!is_executable($pnmtops)) throw new Exception("$pnmtops not executable"); if (!file_exists($pstopdf)) throw new Exception("Package ghostscript not installed"); if (!is_executable($pstopdf)) throw new Exception("$pnmtops not executable"); $cmd = sprintf("cat %s | %s | %s - > %s", escapeshellarg($infile), $pnmtops, $pstopdf, escapeshellarg($outfile)); $this->execute($cmd); } public function mergePDF(Array $infiles, $outfile) { $pdftk = '/usr/bin/pdftk'; if (!file_exists($pdftk)) throw new Exception("Package pdftk not installed"); if (!is_executable($pdftk)) throw new Exception("$pdftk not executable"); $cmd = $pdftk; foreach ($infiles as $infile) $cmd .= ' ' . escapeshellarg($infile); $cmd .= ' cat output ' . escapeshellarg($outfile); $this->execute($cmd); } /***********************************************************************/ protected function execute($cmd) { if (defined('DEBUG') && DEBUG == true) debug($cmd); system($cmd, $ret); if ($ret != 0) { $text = sprintf("Program execution resulted in exit code %d", $ret); error_log($text); error_log($cmd); throw new Exception($text); } return true; } public function getPDF(Array $infiles) { } }