diff --git a/code/scans.php b/code/scans.php index b449d0a..203c4ba 100644 --- a/code/scans.php +++ b/code/scans.php @@ -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); } - $Scan=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 '