Got some variables and errors sorted... posting for cleanup
This commit is contained in:
parent
8e263f5987
commit
6482ce187e
91
index.php
91
index.php
@ -8,7 +8,8 @@
|
|||||||
// FORMATS
|
// FORMATS
|
||||||
$date_format = "Y-m-d_H.i.s"; // Date format to use for file naming - in PHP date code format
|
$date_format = "Y-m-d_H.i.s"; // Date format to use for file naming - in PHP date code format
|
||||||
// PROGRAM LOCATIONS
|
// PROGRAM LOCATIONS
|
||||||
$scanimage = "/usr/bin/scanimage"; // Absolute path to scanimage binary
|
$scanimage = "/usr/bin/scanimage"; //Absolute path to scanimage binary
|
||||||
|
$scanadf = "/usr/bin/scanadf"; // Absolute path to scanadf binary
|
||||||
$convert = "/usr/bin/convert"; //Absolute path to scanimage binary
|
$convert = "/usr/bin/convert"; //Absolute path to scanimage binary
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
@ -34,33 +35,32 @@
|
|||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<legend><h3>Device Setup</h3></legend>
|
<legend><h3>Device Setup</h3></legend>
|
||||||
<label for="device">Device</label>
|
<label for="device">Device</label>
|
||||||
<select id="device" class="pure-input-rounded">
|
<select name="device" id="device" class="pure-input-rounded">
|
||||||
<option value="epkowa:net:pr01.lzu01.point808.com" selected="selected">pr01 (Epson WF-2540)</option>
|
<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>
|
<option value="hpaio:/net/Deskjet_F4500_series?ip=192.168.101.222">pr02 (HP DeskJet F4580)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="source">Feed Source</label>
|
<label for="source">Feed Source</label>
|
||||||
<select id="source" class="pure-input-rounded">
|
<select name="source" id="source" class="pure-input-rounded">
|
||||||
<option value="Automatic Document Feeder" selected="selected">Automatic Document Feeder</option>
|
<option value="Automatic Document Feeder" selected="selected">Automatic Document Feeder</option>
|
||||||
<option value="Flatbed">Flatbed</option>
|
<option value="Flatbed">Flatbed</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="mode">Colors</label>
|
<label for="mode">Colors</label>
|
||||||
<select id="mode" class="pure-input-rounded">
|
<select name="mode" id="mode" class="pure-input-rounded">
|
||||||
<option value="Binary">Black & White</option>
|
<option value="Binary">Black & White</option>
|
||||||
<option value="Gray" selected="selected">Grayscale</option>
|
<option value="Gray" selected="selected">Grayscale</option>
|
||||||
<option value="Color">Color</option>
|
<option value="Color">Color</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="resolution">Resolution</label>
|
<label for="sResolution">Resolution</label>
|
||||||
<select id="resolution" class="pure-input-rounded">
|
<select name="sResolution" id="sResolution" class="pure-input-rounded">
|
||||||
<option value="75">75dpi (FASTEST!)</option>
|
<option value="75" selected="selected">75dpi (FASTEST!)</option>
|
||||||
<option value="300" selected="selected">300dpi (FAST!)</option>
|
<option value="300">300dpi</option>
|
||||||
<option value="600">600dpi (SLOW!)</option>
|
<option value="600">600dpi (SLOW!)</option>
|
||||||
<option value="1200">1200dpi (SLOWEST!)</option>
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="scan" value="yes" />
|
<input type="hidden" name="scan" value="yes" />
|
||||||
@ -70,33 +70,33 @@
|
|||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<legend><h3>File Options</h3></legend>
|
<legend><h3>File Options</h3></legend>
|
||||||
<label for="filetype">File Type</label>
|
<label for="filetype">File Type</label>
|
||||||
<select id="filetype" class="pure-input-rounded">
|
<select name="filetype" id="filetype" class="pure-input-rounded">
|
||||||
<option value="pdf" selected="selected">PDF (multipage)</option>
|
<option value="pdf" selected="selected">PDF (multipage)</option>
|
||||||
<option value="jpg">JPG (image)</option>
|
<option value="jpg">JPG (image)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="filenaming">File Naming</label>
|
<label for="filenaming">File Naming</label>
|
||||||
<input id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
|
<input name="filenaming" type="text" id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1 pure-u-md-1-3">
|
<div class="pure-u-1 pure-u-md-1-3">
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<legend><h3>Page Size</h3></legend>
|
<legend><h3>Page Size (in mm)</h3></legend>
|
||||||
<label for="l">X-Start (top-left, mm)</label>
|
<label for="l">X-Start (top-left)</label>
|
||||||
<input type="number" id="l" class="pure-input-rounded" value="0">
|
<input name="l" type="number" id="l" class="pure-input-rounded" value="0">
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="t">Y-Start (top-left, mm)</label>
|
<label for="t">Y-Start (top-left)</label>
|
||||||
<input type="number" id="t" class="pure-input-rounded" value="0">
|
<input name="t" type="number" id="t" class="pure-input-rounded" value="0">
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="x">Width (mm)</label>
|
<label for="sX">Width (215.9=8.5in)</label>
|
||||||
<input type="number" id="x" class="pure-input-rounded" value="215.9">
|
<input name="sX" type="number" id="sX" class="pure-input-rounded" value="215.9">
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<label for="y">Height (mm)</label>
|
<label for="y">Height (279=11in)</label>
|
||||||
<input type="number" id="y" class="pure-input-rounded" value="279">
|
<input name="y" type="number" id="y" class="pure-input-rounded" value="279">
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
@ -105,20 +105,27 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// initialize scanned files directory path
|
// initialize scanned files directory path
|
||||||
$scans_dir = $app_dir . $scan_dir;
|
$scans_dir = $app_dir . $scan_dir;
|
||||||
|
|
||||||
// append to filename if set, otherwise date only
|
// set post variables
|
||||||
if (isset($_POST["filenaming"])) {
|
if(isset($_POST['sResolution'])) { $pResolution = $_POST['sResolution']; };
|
||||||
$filename = date("Y-m-d_H.i.s")."_".$filenaming;
|
if(isset($_POST['sX'])) { $pX = $_POST['sX']; };
|
||||||
|
|
||||||
|
// decide to use scanimage if Flatbed or scanadf if ADF
|
||||||
|
if (isset($_POST['source'])) {
|
||||||
|
if ($_POST['source']=="Flatbed") {
|
||||||
|
$scanprog = $scanimage;
|
||||||
|
} else {
|
||||||
|
$scanprog = $scanadf;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$filename = date("Y-m-d_H.i.s");
|
$scanprog = $scanimage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// are we being called as a result of a scan or just initial page view?
|
// are we being called as a result of a scan or just initial page view?
|
||||||
if (isset($_POST["scan"])) {
|
if (isset($_POST['scan'])) {
|
||||||
$descriptorspec = array(
|
$descriptorspec = array(
|
||||||
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
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
|
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||||
@ -126,8 +133,19 @@ if (isset($_POST["scan"])) {
|
|||||||
);
|
);
|
||||||
$cwd = '/tmp';
|
$cwd = '/tmp';
|
||||||
$env = array();
|
$env = array();
|
||||||
$process = proc_open("$scanimage -d $_POST[device] --output-file $scans_dir$fileName-%04d --source $_POST[source] --mode ".
|
// append to filename if set, otherwise date only
|
||||||
"$_POST[mode] --resolution $_POST[resolution] -l $_POST[l] -t $_POST[t] -x $_POST[x] -y $_POST[y]", $descriptorspec, $pipes, $cwd, $env);
|
if (isset($_POST['filenaming'])) {
|
||||||
|
if (empty($_POST['filenaming'])) {
|
||||||
|
$filename = date($date_format);
|
||||||
|
} else {
|
||||||
|
$filename = date($date_format)."_".$_POST['filenaming'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filename = date($date_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
// do it!
|
||||||
|
$process = proc_open($scanprog . " -d " . $_POST['device'] . " --output-file " . $scans_dir . $filename . "-%04d --source " . $_POST['source'] . " --mode " . $_POST['mode'] . " --resolution " . $sResolution . " -l " . $_POST['l'] . " -t " . $_POST['t'] . " -x " . $sX . " -y " . $_POST['y'], $descriptorspec, $pipes, $cwd, $env);
|
||||||
if (is_resource($process)) {
|
if (is_resource($process)) {
|
||||||
$errors = stream_get_contents($pipes[2]);
|
$errors = stream_get_contents($pipes[2]);
|
||||||
$output = stream_get_contents($pipes[1]);
|
$output = stream_get_contents($pipes[1]);
|
||||||
@ -136,7 +154,7 @@ if (isset($_POST["scan"])) {
|
|||||||
$inputFiles = array();
|
$inputFiles = array();
|
||||||
$firstFile = "";
|
$firstFile = "";
|
||||||
foreach ($dirList as $file) {
|
foreach ($dirList as $file) {
|
||||||
if (stristr($file, $fileName)) {
|
if (stristr($file, $filename)) {
|
||||||
if ($firstFile=="") $firstFile = $file;
|
if ($firstFile=="") $firstFile = $file;
|
||||||
array_push($inputFiles, $file);
|
array_push($inputFiles, $file);
|
||||||
}
|
}
|
||||||
@ -146,21 +164,26 @@ if (isset($_POST["scan"])) {
|
|||||||
foreach ($inputFiles as $file) {
|
foreach ($inputFiles as $file) {
|
||||||
$path .= "pnm:" . $scans_dir . $file;
|
$path .= "pnm:" . $scans_dir . $file;
|
||||||
}
|
}
|
||||||
$output = `/usr/bin/convert pnm:$scans_dir$firstFile -resize '>300x' -strip $scans_dir$firstFile.jpg`;
|
//exec($convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg");
|
||||||
$output .= `/usr/bin/convert -page a4 $path $scans_dir$fileName.pdf`;
|
// make a (multi-page) pdf file from the scanned pnm files
|
||||||
|
// we have to set density to match the scan resolution and then calculate the width to pixels in order to make the pdf correct
|
||||||
|
exec($convert . ' -density ' . $sResolution . ' -page ' . $sX . ' ' . $path . ' ' . $scans_dir . $filename . '.pdf');
|
||||||
|
|
||||||
|
// $output = $convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg";
|
||||||
|
// $output .= ($convert . " " . $path . " " . $scans_dir . $filename . ".pdf");
|
||||||
echo "Scan Successful!";
|
echo "Scan Successful!";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "Scan Failed! No pages were scanned. Is there a document in the scanner?";
|
echo "Scan Failed! No pages were scanned. Is there a document in the scanner?";
|
||||||
}
|
}
|
||||||
ob_flush();
|
ob_flush();
|
||||||
echo "";
|
echo "";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
<div class="pure-u-1 pure-u-md-1-2">
|
<div class="pure-u-1 pure-u-md-1-2">
|
||||||
<h2>Previous Document Scans (PDF)</h2>
|
<h2>Previous Document Scans (PDF)</h2>
|
||||||
|
5
scans/2014-08-25_18.40.36-0001
Normal file
5
scans/2014-08-25_18.40.36-0001
Normal file
File diff suppressed because one or more lines are too long
5
scans/2014-08-25_18.44.14-0001
Normal file
5
scans/2014-08-25_18.44.14-0001
Normal file
File diff suppressed because one or more lines are too long
5
scans/2014-08-25_18.50.06-0001
Normal file
5
scans/2014-08-25_18.50.06-0001
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user