Add support for PDF format and scanning sizes
This commit is contained in:
@@ -28,33 +28,75 @@ function ShowCommandLog(){
|
||||
}
|
||||
|
||||
|
||||
function Scan($device,$resolution,$format,$destFileBase){
|
||||
function Scan($device,$resolution,$format,$size,$destFileBase){
|
||||
global $PreviewDir;
|
||||
global $ScanImage;
|
||||
global $PNMtoJPEG;
|
||||
global $PNMtoPNG;
|
||||
global $PNMtoPS;
|
||||
global $PStoPDF;
|
||||
|
||||
$DestFile=$PreviewDir.$destFileBase;
|
||||
$Command=$ScanImage." -d ".$device.
|
||||
" --resolution ".$resolution."dpi ";
|
||||
" --resolution ".$resolution."dpi";
|
||||
|
||||
// Apply size
|
||||
if($size=="A4"){
|
||||
$Command.=" -x 210 -y 297";
|
||||
}
|
||||
if($size=="A5Port"){
|
||||
$Command.=" -x 148 -y 210";
|
||||
}
|
||||
if($size=="A5Land"){
|
||||
$Command.=" -x 210 -y 148";
|
||||
}
|
||||
if($size=="Letter"){
|
||||
$Command.=" -x 216 -y 279";
|
||||
}
|
||||
|
||||
// Apply format
|
||||
if($format=="jpg"){
|
||||
$DestFile.=".jpg";
|
||||
$Command.=" | {$PNMtoJPEG} --quality=100 > ".$DestFile;
|
||||
$Scan=ExecCommand($Command);
|
||||
}
|
||||
if($format=="png"){
|
||||
$DestFile.=".png";
|
||||
$Command.=" | {$PNMtoPNG} > ".$DestFile;
|
||||
}
|
||||
$Scan=ExecCommand($Command);
|
||||
}
|
||||
if($format=="pdf"){
|
||||
$DestFile2=$DestFile.".pnm";
|
||||
$Command.=" > {$DestFile2}";
|
||||
$Scan=ExecCommand($Command);
|
||||
|
||||
$DestFile.=".pdf";
|
||||
$Command="cat {$DestFile2} | {$PNMtoPS}";
|
||||
if($size=="A4"){
|
||||
$Command.=" -width=8.3 -height=11.7 ";
|
||||
}
|
||||
if($size=="A5Port"){
|
||||
$Command.=" -width=5.8 -height=8.3 ";
|
||||
}
|
||||
if($size=="A5Land"){
|
||||
$Command.=" -width=8.3 -height=5.8 ";
|
||||
}
|
||||
if($size=="Letter"){
|
||||
$Command.=" -width=8.5 -height=11 ";
|
||||
}
|
||||
$Command.=" | {$PStoPDF} - {$DestFile}";
|
||||
$Convert=ExecCommand($Command);
|
||||
}
|
||||
return $DestFile;
|
||||
}
|
||||
|
||||
function CleanUp(){
|
||||
global $Commands;
|
||||
global $PreviewDir;
|
||||
$Command="rm -rf ".$PreviewDir."*.png";
|
||||
$Delete=ExecCommand($Command);
|
||||
$Command="rm -rf ".$PreviewDir."*.jpg";
|
||||
$Command="rm -rf "
|
||||
.$PreviewDir."*.pnm "
|
||||
.$PreviewDir."*.png "
|
||||
.$PreviewDir."*.jpg "
|
||||
.$PreviewDir."*.pdf ";
|
||||
$Delete=ExecCommand($Command);
|
||||
}
|
||||
|
||||
@@ -85,9 +127,10 @@ unset($start);
|
||||
unset($laenge);
|
||||
|
||||
|
||||
// Override config
|
||||
// Configure with formdata
|
||||
$Resolution=RequestParm("ddlResolution",$Resolution);
|
||||
$Format=RequestParm("ddlFormat",$Format);
|
||||
$Size=RequestParm("ddlSize",$Size);
|
||||
$Crop=RequestParm("chkCrop",$Crop)!=false;
|
||||
$CropFuzz=RequestParm("txtCropFuzz",$CropFuzz);
|
||||
|
||||
@@ -95,14 +138,10 @@ $CropFuzz=RequestParm("txtCropFuzz",$CropFuzz);
|
||||
$DestFile=null;
|
||||
if(RequestParm("btnScan",false)){
|
||||
CleanUp();
|
||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||
$DestFile=Scan($Scanner,$Resolution,$Format,$Size,$baseName);
|
||||
if($Crop){
|
||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
||||
CropImage($DestFile);
|
||||
CropImage($DestFile);
|
||||
}else{
|
||||
$baseName="Scan-".date("Y-m-d_H_i_s");
|
||||
$DestFile=Scan($Scanner,$Resolution,$Format,$baseName);
|
||||
}
|
||||
MoveToDest($DestFile);
|
||||
}
|
||||
@@ -114,7 +153,8 @@ echo '<form id="frmMain" method="GET" action="index.php">'."\n";
|
||||
echo RenderFieldInfo("Scanner",$SaneScanner);
|
||||
echo RenderFieldCombo("Resolution","ddlResolution",$Resolutions,$Resolution);
|
||||
echo RenderFieldCombo("Format","ddlFormat",$Formats,$Format);
|
||||
echo RenderFieldCheckText("Cropping","chkCrop",$Crop,"txtCropFuzz",$CropFuzz);
|
||||
echo RenderFieldCombo("Size","ddlSize",$Sizes,$Size);
|
||||
//echo RenderFieldCheckText("Cropping","chkCrop",$Crop,"txtCropFuzz",$CropFuzz);
|
||||
echo RenderFieldButton("","btnScan","Scan");
|
||||
if($DestFile!=null){
|
||||
$DestFileFixed=htmlentities($DestFile,ENT_HTML5, "UTF-8");
|
||||
|
||||
16
config.php
16
config.php
@@ -7,6 +7,8 @@
|
||||
$ScanImage = "/usr/bin/scanimage";
|
||||
$PNMtoJPEG = "/usr/bin/pnmtojpeg";
|
||||
$PNMtoPNG = "/usr/bin/pnmtopng";
|
||||
$PNMtoPS = "/usr/bin/pnmtops";
|
||||
$PStoPDF = "/usr/bin/ps2pdf14";
|
||||
$ImageMagik = "/usr/bin/convert";
|
||||
|
||||
// Destination dirs
|
||||
@@ -29,12 +31,22 @@ $Resolution=200;
|
||||
// Formats
|
||||
$Formats=array(
|
||||
"PNG"=>"png",
|
||||
"JPEG/JPG"=>"jpg"
|
||||
"JPEG/JPG"=>"jpg",
|
||||
"PDF"=>"pdf"
|
||||
);
|
||||
$Format="png";
|
||||
|
||||
// Size
|
||||
$Sizes=array(
|
||||
"Full"=>"Full",
|
||||
"A4"=>"A4",
|
||||
"A5 Portrait"=>"A5Port",
|
||||
"A5 Landscape"=>"A5Land",
|
||||
"Letter"=>"Letter"
|
||||
);
|
||||
$Size="A4";
|
||||
|
||||
// Cropping
|
||||
$Crop=false;
|
||||
$CropFuzz=50;
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user