(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;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
40
config.php
Normal file
40
config.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/////////
|
||||
// System
|
||||
|
||||
// Executable paths
|
||||
$ScanImage = "/usr/bin/scanimage";
|
||||
$PNMtoJPEG = "/usr/bin/pnmtojpeg";
|
||||
$PNMtoPNG = "/usr/bin/pnmtopng";
|
||||
$ImageMagik = "/usr/bin/convert";
|
||||
|
||||
// Destination dirs
|
||||
$PreviewDir = "temp/";
|
||||
$FinalDestDir = "/store/Escaneos/";
|
||||
|
||||
/////////
|
||||
// Options
|
||||
|
||||
// Resolution
|
||||
$Resolutions=array(
|
||||
"100"=>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;
|
||||
|
||||
?>
|
||||
13
index.php
Normal file
13
index.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scans</title>
|
||||
<link href="style.css" rel="stylesheet" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Scans</h1>
|
||||
<?php
|
||||
include_once "code/scans.php";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
68
style.css
Normal file
68
style.css
Normal file
@@ -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;
|
||||
}
|
||||
0
temp/keep.txt
Normal file
0
temp/keep.txt
Normal file
Reference in New Issue
Block a user