ScanImageWebGUI/index.php
2014-08-25 14:48:02 -04:00

183 lines
6.9 KiB
PHP

<?php
// MAIN CONFIGURATION
$page_title = "Scanimage Web GUI"; // Name to be displayed on top of page as well as page title
$user_message = "Use the drop-downs below to set preferences. Load documents in the feeder and press \"Scan\". When the job completes, you will be able to pick your file from the selection at the bottom of the page."; // Text welcome message for user under title
// DIRECTORIES
$app_dir = "/var/www/scan/"; // Absolute path to where this app directory is - must end with a /
$scan_dir = "scans/"; // Relative path inside application directory that holds the scans - must end with a /
// FORMATS
$date_format = "Y-m-d_H.i.s"; // Date format to use for file naming - in PHP date code format
// PROGRAM LOCATIONS
$scanimage = "/usr/bin/scanimage"; // Absolute path to scanimage binary
$convert = "/usr/bin/convert"; //Absolute path to scanimage binary
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="pure/pure-min.css">
<link rel="stylesheet" href="pure/grids-responsive.css">
<link rel="stylesheet" href="pure/base-min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<?php
// initialize scanned files directory path
$scans_dir = $app_dir . $scan_dir;
// append to filename if set, otherwise date only
if (isset($_POST["filenaming"])) {
$filename = date("Y-m-d_H.i.s")."_".$filenaming;
} else {
$filename = date("Y-m-d_H.i.s");
}
// are we being called as a result of a scan or just initial page view?
if (isset($_POST["scan"])) {
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
$cwd = '/tmp';
$env = array();
$process = proc_open("$scanimage -d $_POST[device] --output-file $scans_dir$fileName-%04d --source $_POST[source] --mode ".
"$_POST[mode] --resolution $_POST[resolution] -l $_POST[l] -t $_POST[t] -x $_POST[x] -y $_POST[y]", $descriptorspec, $pipes, $cwd, $env);
if (is_resource($process)) {
$errors = stream_get_contents($pipes[2]);
$output = stream_get_contents($pipes[1]);
}
$dirList = scandir($scans_dir);
$inputFiles = array();
$firstFile = "";
foreach ($dirList as $file) {
if (stristr($file, $fileName)) {
if ($firstFile=="") $firstFile = $file;
array_push($inputFiles, $file);
}
}
if (count($inputFiles)) {
$path="";
foreach ($inputFiles as $file) {
$path .= "pnm:" . $scans_dir . $file;
}
$output = `/usr/bin/convert pnm:$scans_dir$firstFile -resize '>300x' -strip $scans_dir$firstFile.jpg`;
$output .= `/usr/bin/convert -page a4 $path $scans_dir$fileName.pdf`;
echo "Scan Successful!";
} else {
echo "Scan Failed! No pages were scanned. Is there a document in the scanner?";
}
ob_flush();
echo "";
}
?>
<div class="pure-g">
<div class="pure-u-1">
<h1>Scanner Web GUI</h1>
<p>aa</p>
</div>
</div>
<form class="pure-form pure-form-aligned" action="index.php" method="post">
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<fieldset>
<div class="pure-control-group">
<legend><h3>Device Setup</h3></legend>
<label for="device">Device</label>
<select id="device" class="pure-input-rounded">
<option value="epkowa:net:pr01.lzu01.point808.com" selected="selected">pr01 (Epson WF-2540)</option>
<option value="hpaio:/net/Deskjet_F4500_series?ip=192.168.101.222">pr02 (HP DeskJet F4580)</option>
</select>
</div>
<div class="pure-control-group">
<label for="source">Feed Source</label>
<select id="source" class="pure-input-rounded">
<option value="Automatic Document Feeder" selected="selected">Automatic Document Feeder</option>
<option value="Flatbed">Flatbed</option>
</select>
</div>
<div class="pure-control-group">
<label for="mode">Colors</label>
<select id="mode" class="pure-input-rounded">
<option value="Binary">Black & White</option>
<option value="Gray" selected="selected">Grayscale</option>
<option value="Color">Color</option>
</select>
</div>
<div class="pure-control-group">
<label for="resolution">Resolution</label>
<select id="resolution" class="pure-input-rounded">
<option value="75">75dpi (FASTEST!)</option>
<option value="300" selected="selected">300dpi (FAST!)</option>
<option value="600">600dpi (SLOW!)</option>
<option value="1200">1200dpi (SLOWEST!)</option>
</select>
</div>
<input type="hidden" name="scan" value="yes" />
<input type="submit" onclick="this.disabled=true;this.value='Scanning - PLEASE be patient!';this.form.submit();" value="Scan!" class="pure-button pure-button-primary" />
</div>
<div class="pure-u-1 pure-u-md-1-3">
<div class="pure-control-group">
<legend><h3>File Options</h3></legend>
<label for="filetype">File Type</label>
<select id="filetype" class="pure-input-rounded">
<option value="pdf" selected="selected">PDF (multipage)</option>
<option value="jpg">JPG (image)</option>
</select>
</div>
<div class="pure-control-group">
<label for="filenaming">File Naming</label>
<input id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
</div>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<div class="pure-control-group">
<legend><h3>Page Size</h3></legend>
<label for="l">X-Start (top-left, mm)</label>
<input type="number" id="l" class="pure-input-rounded" value="0">
</div>
<div class="pure-control-group">
<label for="t">Y-Start (top-left, mm)</label>
<input type="number" id="t" class="pure-input-rounded" value="0">
</div>
<div class="pure-control-group">
<label for="x">Width (mm)</label>
<input type="number" id="x" class="pure-input-rounded" value="215.9">
</div>
<div class="pure-control-group">
<label for="y">Height (mm)</label>
<input type="number" id="y" class="pure-input-rounded" value="279">
</div>
</fieldset>
</div>
</div>
</form>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2">
<h2>Previous Document Scans (PDF)</h2>
<?php
$phpfiles = array_reverse(glob($scan_dir . "*.pdf"));
foreach($phpfiles as $phpfile) {
echo "<a target=\"_blank\" href=$phpfile>".basename($phpfile)."</a><br />";
}
?>
</div>
<div class="pure-u-1 pure-u-md-1-2">
<h2>Previous Image Scans (JPG)</h2>
<?php
$phpfiles = array_reverse(glob($scan_dir . "*.jpg"));
foreach($phpfiles as $phpfile) {
echo "<a target=\"_blank\" href=$phpfile>".basename($phpfile)."</a><br />";
}
?>
</div>
</body>
</html>