Initial commit
This commit is contained in:
@@ -3,13 +3,35 @@
|
|||||||
include_once "config.php";
|
include_once "config.php";
|
||||||
include_once "utils.php";
|
include_once "utils.php";
|
||||||
|
|
||||||
|
$Commands=array();
|
||||||
|
|
||||||
|
function ExecCommand($command){
|
||||||
|
global $Commands;
|
||||||
|
$loggedCommand=array();
|
||||||
|
$loggedCommand["Command"]=$command;
|
||||||
|
list($returnCode, $stdout, $stderr)=ExecFull($command);
|
||||||
|
$loggedCommand["Result"]=$stdout;
|
||||||
|
$loggedCommand["Error"]=$stderr;
|
||||||
|
$loggedCommand["ReturnCode"]=$returnCode;
|
||||||
|
$Commands[]=$loggedCommand;
|
||||||
|
return $stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ShowCommandLog(){
|
||||||
|
global $Commands;
|
||||||
|
foreach($Commands as $loggedCommand){
|
||||||
|
DrawParagraph($loggedCommand["Command"],"font-weight: bold;");
|
||||||
|
DrawParagraph($loggedCommand["Result"]);
|
||||||
|
DrawParagraph($loggedCommand["Error"],"color: red;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function Scan($device,$resolution,$format,$destFileBase){
|
function Scan($device,$resolution,$format,$destFileBase){
|
||||||
global $PreviewDir;
|
global $PreviewDir;
|
||||||
global $ScanImage;
|
global $ScanImage;
|
||||||
global $PNMtoJPEG;
|
global $PNMtoJPEG;
|
||||||
global $PNMtoPNG;
|
global $PNMtoPNG;
|
||||||
global $PNMtoPS;
|
|
||||||
global $PStoPDF;
|
|
||||||
|
|
||||||
$DestFile=$PreviewDir.$destFileBase;
|
$DestFile=$PreviewDir.$destFileBase;
|
||||||
$Command=$ScanImage." -d ".$device.
|
$Command=$ScanImage." -d ".$device.
|
||||||
@@ -17,35 +39,22 @@ function Scan($device,$resolution,$format,$destFileBase){
|
|||||||
if($format=="jpg"){
|
if($format=="jpg"){
|
||||||
$DestFile.=".jpg";
|
$DestFile.=".jpg";
|
||||||
$Command.=" | {$PNMtoJPEG} --quality=100 > ".$DestFile;
|
$Command.=" | {$PNMtoJPEG} --quality=100 > ".$DestFile;
|
||||||
$Scan=shell_exec($Command);
|
|
||||||
}
|
}
|
||||||
if($format=="png"){
|
if($format=="png"){
|
||||||
$DestFile.=".png";
|
$DestFile.=".png";
|
||||||
$Command.=" | {$PNMtoPNG} > ".$DestFile;
|
$Command.=" | {$PNMtoPNG} > ".$DestFile;
|
||||||
$Scan=shell_exec($Command);
|
|
||||||
}
|
|
||||||
if($format=="pdf"){
|
|
||||||
$DestFile2=$DestFile.".pnm";
|
|
||||||
$Command.=" > {$DestFile2}";
|
|
||||||
$Scan=shell_exec($Command);
|
|
||||||
|
|
||||||
$DestFile.=".pdf";
|
|
||||||
$Command="cat {$DestFile2} | {$PNMtoPS} | {$PStoPDF} - {$DestFile}";
|
|
||||||
$Convert=shell_exec($Command);
|
|
||||||
}
|
}
|
||||||
|
$Scan=ExecCommand($Command);
|
||||||
return $DestFile;
|
return $DestFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CleanUp(){
|
function CleanUp(){
|
||||||
|
global $Commands;
|
||||||
global $PreviewDir;
|
global $PreviewDir;
|
||||||
$Command="rm -rf ".$PreviewDir."*.pnm";
|
|
||||||
$Delete=shell_exec($Command);
|
|
||||||
$Command="rm -rf ".$PreviewDir."*.png";
|
$Command="rm -rf ".$PreviewDir."*.png";
|
||||||
$Delete=shell_exec($Command);
|
$Delete=ExecCommand($Command);
|
||||||
$Command="rm -rf ".$PreviewDir."*.jpg";
|
$Command="rm -rf ".$PreviewDir."*.jpg";
|
||||||
$Delete=shell_exec($Command);
|
$Delete=ExecCommand($Command);
|
||||||
$Command="rm -rf ".$PreviewDir."*.pdf";
|
|
||||||
$Delete=shell_exec($Command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function MoveToDest($origFile){
|
function MoveToDest($origFile){
|
||||||
@@ -53,20 +62,20 @@ function MoveToDest($origFile){
|
|||||||
$destFile=basename($origFile);
|
$destFile=basename($origFile);
|
||||||
$destFile=$FinalDestDir.$destFile;
|
$destFile=$FinalDestDir.$destFile;
|
||||||
$Command="cp ".$origFile." ".$destFile;
|
$Command="cp ".$origFile." ".$destFile;
|
||||||
$Copy=shell_exec($Command);
|
$Copy=ExecCommand($Command);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CropImage($file){
|
function CropImage($file){
|
||||||
global $ImageMagik;
|
global $ImageMagik;
|
||||||
global $CropFuzz;
|
global $CropFuzz;
|
||||||
$Command=$ImageMagik." ".$file.' -fuzz '.$CropFuzz.'% -trim '.$file."\n";
|
$Command=$ImageMagik." ".$file.' -fuzz '.$CropFuzz.'% -trim '.$file."\n";
|
||||||
$Cropping=shell_exec($Command);
|
$Cropping=ExecCommand($Command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Detect scanner
|
// Detect scanner
|
||||||
$CMD=$ScanImage." --list-devices | grep device";
|
$CMD=$ScanImage." --list-devices | grep device";
|
||||||
$SaneScanner = `$CMD`;
|
$SaneScanner = ExecCommand($CMD);
|
||||||
unset($cmd);
|
unset($cmd);
|
||||||
$start=strpos($SaneScanner,"`")+1;
|
$start=strpos($SaneScanner,"`")+1;
|
||||||
$laenge=strpos($SaneScanner,"'")-$start;
|
$laenge=strpos($SaneScanner,"'")-$start;
|
||||||
@@ -89,6 +98,7 @@ if(RequestParm("btnScan",false)){
|
|||||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||||
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
||||||
CropImage($DestFile);
|
CropImage($DestFile);
|
||||||
|
CropImage($DestFile);
|
||||||
}else{
|
}else{
|
||||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||||
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
||||||
@@ -114,5 +124,5 @@ if($DestFile!=null){
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
|
ShowCommandLog();
|
||||||
?>
|
?>
|
||||||
@@ -90,6 +90,14 @@ function DrawButton($text,$id){
|
|||||||
'id="'.$idFixed.'" name="'.$idFixed.'" class="button" />';
|
'id="'.$idFixed.'" name="'.$idFixed.'" class="button" />';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DrawParagraph($text,$style=null){
|
||||||
|
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||||
|
if($style==null){
|
||||||
|
echo "<p>".$textFixed."</p>\n";
|
||||||
|
}else{
|
||||||
|
echo "<p style=\"".$style."\">".$textFixed."</p>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function RequestParm($name,$defaultValue){
|
function RequestParm($name,$defaultValue){
|
||||||
if(isset($_GET[$name])){
|
if(isset($_GET[$name])){
|
||||||
@@ -101,5 +109,22 @@ function RequestParm($name,$defaultValue){
|
|||||||
return $defaultValue;
|
return $defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ExecFull($cmd, $input='') {
|
||||||
|
$proc = proc_open($cmd, array(array('pipe', 'r'),
|
||||||
|
array('pipe', 'w'),
|
||||||
|
array('pipe', 'w')), $pipes);
|
||||||
|
fwrite($pipes[0], $input);
|
||||||
|
fclose($pipes[0]);
|
||||||
|
|
||||||
|
$stdout = stream_get_contents($pipes[1]);
|
||||||
|
fclose($pipes[1]);
|
||||||
|
|
||||||
|
$stderr = stream_get_contents($pipes[2]);
|
||||||
|
fclose($pipes[2]);
|
||||||
|
|
||||||
|
$return_code = (int)proc_close($proc);
|
||||||
|
|
||||||
|
return array($return_code, $stdout, $stderr);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
$ScanImage = "/usr/bin/scanimage";
|
$ScanImage = "/usr/bin/scanimage";
|
||||||
$PNMtoJPEG = "/usr/bin/pnmtojpeg";
|
$PNMtoJPEG = "/usr/bin/pnmtojpeg";
|
||||||
$PNMtoPNG = "/usr/bin/pnmtopng";
|
$PNMtoPNG = "/usr/bin/pnmtopng";
|
||||||
$PNMtoPS = "/usr/bin/pnmtops";
|
|
||||||
$PStoPDF = "/usr/bin/ps2pdf14";
|
|
||||||
$ImageMagik = "/usr/bin/convert";
|
$ImageMagik = "/usr/bin/convert";
|
||||||
|
|
||||||
// Destination dirs
|
// Destination dirs
|
||||||
@@ -31,8 +29,7 @@ $Resolution=200;
|
|||||||
// Formats
|
// Formats
|
||||||
$Formats=array(
|
$Formats=array(
|
||||||
"PNG"=>"png",
|
"PNG"=>"png",
|
||||||
"JPEG/JPG"=>"jpg",
|
"JPEG/JPG"=>"jpg"
|
||||||
"PDF"=>"pdf"
|
|
||||||
);
|
);
|
||||||
$Format="png";
|
$Format="png";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user