(2013-12-01)
This commit is contained in:
103
code/scans.php
Normal file
103
code/scans.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
include_once "config.php";
|
||||
include_once "utils.php";
|
||||
|
||||
function Scan($device,$resolution,$format,$destFileBase){
|
||||
global $PreviewDir;
|
||||
global $ScanImage;
|
||||
global $PNMtoJPEG;
|
||||
global $PNMtoPNG;
|
||||
|
||||
$DestFile=$PreviewDir.$destFileBase;
|
||||
$Command=$ScanImage." -d ".$device.
|
||||
" --resolution ".$resolution."dpi ";
|
||||
if($format=="jpg"){
|
||||
$DestFile.=".jpg";
|
||||
$Command.=" | {$PNMtoJPEG} --quality=100 > ".$DestFile;
|
||||
}
|
||||
if($format=="png"){
|
||||
$DestFile.=".png";
|
||||
$Command.=" | {$PNMtoPNG} > ".$DestFile;
|
||||
}
|
||||
$Scan=shell_exec($Command);
|
||||
return $DestFile;
|
||||
}
|
||||
|
||||
function CleanUp(){
|
||||
global $PreviewDir;
|
||||
$Command="rm -rf ".$PreviewDir."*.png";
|
||||
$Delete=shell_exec($Command);
|
||||
$Command="rm -rf ".$PreviewDir."*.jpg";
|
||||
$Delete=shell_exec($Command);
|
||||
}
|
||||
|
||||
function MoveToDest($origFile){
|
||||
global $FinalDestDir;
|
||||
$destFile=basename($origFile);
|
||||
$destFile=$FinalDestDir.$destFile;
|
||||
$Command="cp ".$origFile." ".$destFile;
|
||||
$Copy=shell_exec($Command);
|
||||
}
|
||||
|
||||
function CropImage($file){
|
||||
global $ImageMagik;
|
||||
global $CropFuzz;
|
||||
$Command=$ImageMagik." ".$file.' -fuzz '.$CropFuzz.'% -trim '.$file."\n";
|
||||
$Cropping=shell_exec($Command);
|
||||
}
|
||||
|
||||
|
||||
// Detect scanner
|
||||
$CMD=$ScanImage." --list-devices | grep device";
|
||||
$SaneScanner = `$CMD`;
|
||||
unset($cmd);
|
||||
$start=strpos($SaneScanner,"`")+1;
|
||||
$laenge=strpos($SaneScanner,"'")-$start;
|
||||
$Scanner = "\"".substr($SaneScanner,$start,$laenge)."\"";
|
||||
unset($start);
|
||||
unset($laenge);
|
||||
|
||||
|
||||
// Override config
|
||||
$Resolution=RequestParm("ddlResolution",$Resolution);
|
||||
$Format=RequestParm("ddlFormat",$Format);
|
||||
$Crop=RequestParm("chkCrop",$Crop)!=false;
|
||||
$CropFuzz=RequestParm("txtCropFuzz",$CropFuzz);
|
||||
|
||||
// Preprocess
|
||||
$DestFile=null;
|
||||
if(RequestParm("btnScan",false)){
|
||||
CleanUp();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
echo '<form id="frmMain" method="GET" action="index.php">'."\n";
|
||||
|
||||
// Render header info
|
||||
DrawFieldInfo("Scanner",$SaneScanner);
|
||||
DrawFieldCombo("Resolution","ddlResolution",$Resolutions,$Resolution);
|
||||
DrawFieldCombo("Format","ddlFormat",$Formats,$Format);
|
||||
//DrawFieldCheckText("Cropping","chkCrop",$Crop,"txtCropFuzz",$CropFuzz);
|
||||
DrawButton("Scan","btnScan");
|
||||
if($DestFile!=null){
|
||||
$DestFileFixed=htmlentities($DestFile,ENT_HTML5, "UTF-8");
|
||||
echo '<div><a href="'.$DestFileFixed.'">'.
|
||||
'Download '.$DestFileFixed.'</a></div>'."\n";
|
||||
echo '<div><img alt="preview" src="'.$DestFileFixed.'" '.
|
||||
'class="previewImage" /></div>';
|
||||
}
|
||||
|
||||
echo "</form>\n";
|
||||
|
||||
?>
|
||||
105
code/utils.php
Normal file
105
code/utils.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
function DrawFieldInfo($text,$info){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$infoFixed=htmlentities($info,ENT_HTML5, "UTF-8");
|
||||
echo '<div class="field">'."\n";
|
||||
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
|
||||
echo '<div class="fieldText">'.$infoFixed."</div>\n";
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
function DrawFieldCombo($text,$id,$options,$selected){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
|
||||
echo '<div class="field">'."\n";
|
||||
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
|
||||
echo '<div class="fieldCombo">'."\n";
|
||||
echo '<select id="'.$idFixed.'" name="'.$idFixed.'" '.
|
||||
'class="combo">'."\n";
|
||||
foreach ($options as $key => $value) {
|
||||
$keyFixed=htmlentities($key,ENT_HTML5, "UTF-8");
|
||||
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
|
||||
if($value==$selected){
|
||||
echo '<option value="'.$valueFixed.
|
||||
'" title="'.$valueFixed.'" selected >'.
|
||||
$keyFixed."</option>/n";
|
||||
}else{
|
||||
echo '<option value="'.$valueFixed.
|
||||
'" title="'.$valueFixed.'">'.
|
||||
$keyFixed."</option>/n";
|
||||
}
|
||||
}
|
||||
echo "</select>\n";
|
||||
echo "</div>\n";
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
function DrawFieldText($text,$idText,$value){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
|
||||
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
|
||||
echo '<div class="field">'."\n";
|
||||
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
|
||||
echo '<div class="fieldText">'."\n";
|
||||
echo '<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'"'.
|
||||
' value="'.$valueFixed.'" '.
|
||||
' class="textBox"/>'."\n";
|
||||
echo "</div>\n";
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
function DrawFieldCheck($text,$idCheck,$checked,$value){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
|
||||
$valueFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
|
||||
echo '<div class="field">'."\n";
|
||||
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
|
||||
echo '<div class="fieldCombo">'."\n";
|
||||
echo '<input type="checkbox" id="'.$idCheckFixed.'" '.
|
||||
'name="'.$idCheckFixed.'" ';
|
||||
if($checked){ echo " checked "; }
|
||||
echo 'class="check">'.$valueFixed."\n";
|
||||
echo "</input>\n";
|
||||
echo "</div>\n";
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
function DrawFieldCheckText($text,$idCheck,$checked,$idText,$value){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$idCheckFixed=htmlentities($idCheck,ENT_HTML5, "UTF-8");
|
||||
$idTextFixed=htmlentities($idText,ENT_HTML5, "UTF-8");
|
||||
$valueFixed=htmlentities($value,ENT_HTML5, "UTF-8");
|
||||
echo '<div class="field">'."\n";
|
||||
echo '<span class="fieldLabel">'.$textFixed.":</span>\n";
|
||||
echo '<div class="fieldCombo">'."\n";
|
||||
echo '<input type="checkbox" id="'.$idCheckFixed.'" '.
|
||||
'name="'.$idCheckFixed.'" ';
|
||||
if($checked){ echo " checked "; }
|
||||
echo 'class="check" />'."\n";
|
||||
echo '<input type="text" id="'.$idTextFixed.'" name="'.$idTextFixed.'" '.
|
||||
'value="'.$valueFixed.'" class="textBox" />';
|
||||
echo "</div>\n";
|
||||
echo '</div>'."\n";
|
||||
}
|
||||
|
||||
function DrawButton($text,$id){
|
||||
$textFixed=htmlentities($text,ENT_HTML5, "UTF-8");
|
||||
$idFixed=htmlentities($id,ENT_HTML5, "UTF-8");
|
||||
echo '<input type="submit" value="'.$textFixed.'" '.
|
||||
'id="'.$idFixed.'" name="'.$idFixed.'" class="button" />';
|
||||
}
|
||||
|
||||
|
||||
function RequestParm($name,$defaultValue){
|
||||
if(isset($_GET[$name])){
|
||||
return $_GET[$name];
|
||||
}
|
||||
if(isset($_POST[$name])){
|
||||
return $_POST[$name];
|
||||
}
|
||||
return $defaultValue;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user