<?php
################## Config ################################
$deleteFilesFromTemp = true; # true, false
$gamma = '.3'; # 0..1 as String
$showType = 'jpg'; # 'jpg', 'tiff', 'pdf'
##########################################################
$scanImage = new scanImage ( $deleteFilesFromTemp, $gamma, $showType);
$scanImage -> scan();
class scanImage {
public $deleteFilesFromTemp = true;
public $gamma = '.3';
public $showType = 'jpg';
public $scanner = false;
function __construct( $deleteFilesFromTemp = true, $gamma = '.3', $showType = 'jpg' ) {
$this -> deleteFilesFromTemp = $deleteFilesFromTemp;
$this -> gamma = $gamma;
$this -> showType = $showType;
if ( ! isset( $_SESSION['scannerDevice'] ) || '' == $_SESSION['scannerDevice'] ) {
# Init: Suchen des devices
$scanner = trim( `scanimage
-L
| grep
"^device"`
);
if ( $scanner ) {
$_SESSION['scannerDevice'] = $scanner;
} else {
$_SESSION['scannerDevice'] = false;
unset( $_SESSION['scannerDevice'] );
print "Kein Scanner gefunden.";
}
} else {
$this -> scanner = $_SESSION['scannerDevice'];
}
}
function scan() {
$scanner = $_SESSION['scannerDevice'];
$gamma = $this -> gamma;
$t=`ps ax | grep "scanimage -d $scanner" | grep -v "ps ax" | wc -l`;
die ("($t) Der Scanner ist aktiv. Warten Sie eine Weile und <a href='#'>laden Sie dann diese Seite erneut.</a>");
}
$unixTime = date( 'Y-m-d_His' );
$tmpfile_tiff = '/tmp/' . $unixTime . '.tiff';
$dummy=`/usr/bin/scanimage -x 210 -y 297 --format tiff -d $scanner > $tmpfile_tiff`;
switch ( $this -> showType ) {
case 'tiff':
header( 'Content-Type: image/tiff' );
header( 'Content-Disposition: attachment; filename="' . $unixTime . '.tiff' . '"' );
break;
case 'jpg':
$tmpfile_jpg = '/tmp/' . $unixTime . '.jpg';
$dummy=`/usr/bin/convert -gamma $gamma -auto-level -despeckle $tmpfile_tiff $tmpfile_jpg`;
header( 'Content-Type: image/jpg' );
break;
case 'pdf':
$tmpfile_pdf = '/tmp/' . $unixTime . '.pdf';
$dummy=`tiff2pdf -o $tmpfile_pdf -j -b -p A4 -f $tmpfile_tiff`;
header( 'Content-Type: application/pdf' );
header( 'Content-Disposition: inline; filename="' . $unixTime . '.pdf' . '"' );
break;
default:
echo "Konfigurationsfehler. Sie (oder ein Admin) haben (hat) einen unzulässigen Dateityp eingestellt.";
break;
}
if ( $this -> deleteFilesFromTemp ) {
}
}
}