From f1d57332ef2ee045eccbc036831834ee0c1c9b0c Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sun, 1 Dec 2013 00:00:00 +0100 Subject: [PATCH] (2013-12-01) --- code/scans.php | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ code/utils.php | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ config.php | 40 +++++++++++++++++++ index.php | 13 ++++++ style.css | 68 ++++++++++++++++++++++++++++++++ temp/keep.txt | 0 6 files changed, 329 insertions(+) create mode 100644 code/scans.php create mode 100644 code/utils.php create mode 100644 config.php create mode 100644 index.php create mode 100644 style.css create mode 100644 temp/keep.txt diff --git a/code/scans.php b/code/scans.php new file mode 100644 index 0000000..36a99dd --- /dev/null +++ b/code/scans.php @@ -0,0 +1,103 @@ + ".$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 '
'."\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 '
'. + 'Download '.$DestFileFixed.'
'."\n"; + echo '
preview
'; +} + +echo "
\n"; + +?> \ No newline at end of file diff --git a/code/utils.php b/code/utils.php new file mode 100644 index 0000000..9793f3a --- /dev/null +++ b/code/utils.php @@ -0,0 +1,105 @@ +'."\n"; + echo ''.$textFixed.":\n"; + echo '
'.$infoFixed."
\n"; + echo ''."\n"; +} + +function DrawFieldCombo($text,$id,$options,$selected){ + $textFixed=htmlentities($text,ENT_HTML5, "UTF-8"); + $idFixed=htmlentities($id,ENT_HTML5, "UTF-8"); + echo '
'."\n"; + echo ''.$textFixed.":\n"; + echo '
'."\n"; + echo '\n"; + echo "
\n"; + echo '
'."\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 '
'."\n"; + echo ''.$textFixed.":\n"; + echo '
'."\n"; + echo ''."\n"; + echo "
\n"; + echo '
'."\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 '
'."\n"; + echo ''.$textFixed.":\n"; + echo '
'."\n"; + echo ''.$valueFixed."\n"; + echo "\n"; + echo "
\n"; + echo '
'."\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 '
'."\n"; + echo ''.$textFixed.":\n"; + echo '
'."\n"; + echo ''."\n"; + echo ''; + echo "
\n"; + echo '
'."\n"; +} + +function DrawButton($text,$id){ + $textFixed=htmlentities($text,ENT_HTML5, "UTF-8"); + $idFixed=htmlentities($id,ENT_HTML5, "UTF-8"); + echo ''; +} + + +function RequestParm($name,$defaultValue){ + if(isset($_GET[$name])){ + return $_GET[$name]; + } + if(isset($_POST[$name])){ + return $_POST[$name]; + } + return $defaultValue; +} + + +?> \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 0000000..ee4c77e --- /dev/null +++ b/config.php @@ -0,0 +1,40 @@ +100, + "150"=>150, + "200"=>200, + "300"=>300, + "600"=>600 +); +$Resolution=200; + +// Formats +$Formats=array( + "PNG"=>"png", + "JPEG/JPG"=>"jpg" +); +$Format="png"; + +// Cropping +$Crop=false; +$CropFuzz=50; + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..38a17b5 --- /dev/null +++ b/index.php @@ -0,0 +1,13 @@ + + + +Scans + + + +

Scans

+ + + diff --git a/style.css b/style.css new file mode 100644 index 0000000..93ebe5f --- /dev/null +++ b/style.css @@ -0,0 +1,68 @@ + * {margin:0;padding:0;border:none;font-family:Arial,sans-serif; color:rgb(32,32,32);background-color:white; box-sizing:border-box; -moz-box-sizing:border-box;} + h1{ + font-size: 30px; + color: rgb(128,128,128); + margin:5px; + margin-top:10px; + } + h1:first-child{ + margin-top:5px; + } + + .field{ + display:block; + white-space:nowrap; + vertical-align:top; + font-size:0; + margin:5px; + margin-top:10px; + } + .field:first-child{ + margin-top:5px; + } + .fieldLabel{ + display:inline-block; + width:20%; + font-weight: bold; + vertical-align:top; + white-space: normal; + word-break: break-word; + font-size:14px; + } + .fieldText, + .fieldCombo{ + display:inline-block; + width:80%; + white-space: normal; + vertical-align:top; + word-break: break-word; + font-size:14px; + } + + .combo{ + min-width:100px; + border: solid 1px rgb(32,32,32); + } + + .button{ + display:inline-block; + padding:5px; + margin:5px; + background-color: rgb(192,192,192); + border: solid 1px rgb(32,32,32); + cursor:pointer; + } + .button:hover{ + background-color: rgb(240,240,240); + } + + .textBox{ + border: solid 1px rgb(32,32,32); + } + + .previewImage{ + margin:5px; + border: solid 1px rgb(32,32,32); + max-width:200px; + max-height:200px; + } \ No newline at end of file diff --git a/temp/keep.txt b/temp/keep.txt new file mode 100644 index 0000000..e69de29