Raketenwilli: Wer hat Linux, PHP und einen Scanner? (Ich brauch mal Hilfe....)

Ich schreibe gerade ein PHP-Skript zum Einscannen von Dokumenten/Bildern und brauche dazu ein wenig Hilfe.

Helfen kann, wer Linux, PHP und einen Scanner hat.

Das Skript stellt fest, welche Scanner erreichbar sind und ermittelt deren Eigenschaften. Diese müssen aber „geparst“ werden, wozu ich leider nur die Daten meines Scanners habe.

  • Ich hätte gerne weitere Scanner damit getestet.

Wer es ausführt muss Mitglied der Gruppe „sane“ scanner sein (also scannen können. Das Skript ändert nichts am System.

Bitte in einem Terminal ausführen, die Ausgaben posten.

Das Skript läuft, ist aber nicht fertig (Es fehlen z.B. auch noch Fehlerbehandlungen). Deshalb habe ich es als „bad“ markiert

<?php

class allScanners {
	
	public $scanners;
	
	function __construct() {
		
		$output = `/usr/bin/scanimage -L 2> /dev/null`;
		$lines  = explode ("\n", $output);
		foreach ( $lines as $line ) {
			$line = trim( $line );
			if ( $line ) {
				$device = str_replace( 'device `', '', $line );
				$device = preg_replace('/\'.*$/', '', $device );
				$name   = preg_replace('/^.* is a /', '', $line );
				$name   = preg_replace('/ scanner$/', '', $name );
				$this->scanners[$device]['name'] = $name;
			}
		}
		foreach ( array_keys( $this->scanners ) as $device ) {
			
			$output = `scanimage --help -Av -d "$device" 2> /dev/null| grep -P 'All options specific to device|^ +-'`;
			echo '-----------------------------------------------------------' . PHP_EOL;
			echo $output. PHP_EOL;
			echo '-----------------------------------------------------------' . PHP_EOL;
			$isHelp = true;
			foreach ( explode("\n", $output ) as $line ) {
				$line = trim( $line );
				if ( $line ) {
					if ( $isHelp ) {
						if ( 0 === strpos( $line, 'All options' ) ) {
							$isHelp = false;
						}
					} else {
						list( $optionName, $optionString ) = explode( ' ', $line, 2 );
						$optionName=trim($optionName, '-');
						switch ( $optionName ) {
							case "l":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueFromTo( $optionName, $optionString );
								break;
							case "t":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueFromTo( $optionName, $optionString );
								break;
							case "x":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueFromTo( $optionName, $optionString );
								break;
							case "y":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueFromTo( $optionName, $optionString );
								break;
							case "resolution":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueList( $optionName, $optionString );
								break;
							case "mode":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueList( $optionName, $optionString );
								break;
							case "source":
								$this->scanners[$device]['options'][$optionName] = $this->parseValueList( $optionName, $optionString );
								break;
							default:
								user_error( "Unbekannte Option: '${optionName}' mit String '${optionString}'", E_USER_NOTICE );
						}
					}
				}
			}
		}
	}
	
	function parseValueFromTo( $optionName, $s ) {
		$ret = [];
		$FromTo = false;
		$default = false;
		list( $FromTo, $default) = explode( ' ', trim( $s ), 2 );
		if ( $FromTo and $default) {
			list( $ret['min'], $ret['max'] ) = explode( '..', $FromTo, 2 );
			$ret['type'] = 'FromTo';
			$ret['min'] = floatval( $ret['min'] );
			$ret['max'] = floatval( $ret['max'] );
			$ret['default'] = floatval( trim('[', trim( ']', $default) ) );
			return $ret;
		} else {
			user_error( "Werte für Option ${optionName} sind nicht feststellbar", E_USER_NOTICE );
			return false;
		}
		
	}
	
	function parseValueList( $optionName, $s ) {
		$ret = [];
		$s = trim( $s );
		
		$ret['type'] = 'ValueList';
		$ret['default'] = false;
		$ret['options'] = false;

		$o = preg_replace( '/ \[.*\]$/', '', $s );
		$o = preg_replace( '/dpi$/', '', $o );
		$ret['options'] = explode('|', $o);
		
		$ret['default'] = preg_replace( '/^.*\[/', '', $s );
		$ret['default'] = trim( $ret['default'], ']' );		
		
		return $ret;
	}
}

$sallScanners = new allScanners();
print_r ($sallScanners);

Ziel ist übrigens, einen Raspi oder dergleichen mit einem nicht netzwerkfähigen Scanner zu verknüpfen und dann das Scannen via http[s] anzubieten.

  1. Lieber Raketenwilli,

    Ziel ist übrigens, einen Raspi oder dergleichen mit einem nicht netzwerkfähigen Scanner zu verknüpfen und dann das Scannen via http[s] anzubieten.

    warum genügt es Dir nicht, einen passenden Printserver auf dem Raspi einzusetzen? Schnelles Suchen liefert mir: https://pimylifeup.com/raspberry-pi-print-server/

    Liebe Grüße

    Felix Riesterer

    1. Lieber Felix,

      wer lesen kann, ist klar im Vorteil. Es ging nicht um Drucker, sondern um Scanner. Das ist nicht wirklich das Gleiche... :-/

      Liebe Grüße

      Felix Riesterer

      1. Naja. Mit cups und samba komme ich gut klar :-)

        Aber etwas wie

        scanimage --help -Av -d "BrotherADS2200:libusb:001:009"
        

        liefert Ergebnisse, die halt vom Scanner und dessen Treiber abhängen und „geparst“ werden müssen, damit ich ein Formular bauen kann, mit dessen Hilfe man dann wieder so scannen kann wie man es will…

        Deshalb brauche ich Vergleichsdaten von Scannern.

  2. Es geht auch ohne PHP. Handlungsanleitung:

    ~> LANG=c /usr/bin/scanimage -L 2> /dev/null
    

    liefert bei mir folgende Ausgabe:

    device `BrotherADS2200:libusb:001:009' is a Brother ADS2200 USB scanner
    

    (Werden mehrere Scanner erkannt, dann gibt es auch mehr Ausgabezeilen.)

    „BrotherADS2200:libusb:001:009“ ist bei mir der Gerätename.

    Mit diesem dann also:

    ~> LANG=c scanimage --help -Av -d "BrotherADS2200:libusb:001:009" 2> /dev/null
    

    Ich brauche die Ausgaben wirklich…

    1. gudn tach!

      $ scanimage --help -Av -d "brother2:bus1;dev1"
      Usage: scanimage [OPTION]...
      
      Start image acquisition on a scanner device and write image data to
      standard output.
      
      Parameters are separated by a blank from single-character options (e.g.
      -d epson) and by a "=" from multi-character options (e.g. --device-name=epson).
      -d, --device-name=DEVICE   use a given scanner device (e.g. hp:/dev/scanner)
          --format=pnm|tiff|png|jpeg  file format of output file
      -i, --icc-profile=PROFILE  include this ICC profile into TIFF file
      -L, --list-devices         show available scanner devices
      -f, --formatted-device-list=FORMAT similar to -L, but the FORMAT of the output
                                 can be specified: %d (device name), %v (vendor),
                                 %m (model), %t (type), %i (index number), and
                                 %n (newline)
      -b, --batch[=FORMAT]       working in batch mode, FORMAT is `out%d.pnm' `out%d.tif'
                                 `out%d.png' or `out%d.jpg' by default depending on --format
                                 This option is incompatible with --output-file.    --batch-start=#        page number to start naming files with
          --batch-count=#        how many pages to scan in batch mode
          --batch-increment=#    increase page number in filename by #
          --batch-double         increment page number by two, same as
                                 --batch-increment=2
          --batch-print          print image filenames to stdout
          --batch-prompt         ask for pressing a key before scanning a page
          --accept-md5-only      only accept authorization requests using md5
      -p, --progress             print progress messages
      -o, --output-file=PATH     save output to the given file instead of stdout.
                                 This option is incompatible with --batch.
      -n, --dont-scan            only set options, don't actually scan
      -T, --test                 test backend thoroughly
      -A, --all-options          list all available backend options
      -h, --help                 display this help message and exit
      -v, --verbose              give even more status messages
      -B, --buffer-size=#        change input buffer size (in kB, default 32)
      -V, --version              print version information
      Output format is not set, using pnm as a default.
      scanimage: rounded value of br-x from 215.9 to 215.88
      scanimage: rounded value of br-y from 355.6 to 355.567
      
      Options specific to device `brother2:bus1;dev1':
        Mode:
          --mode Black & White|Gray[Error Diffusion]|True Gray|24bit Color|24bit Color[Fast] [24bit Color]
              Select the scan mode
          --resolution 100|150|200|300|400|600|1200|2400|4800|9600dpi [200]
              Sets the resolution of the scanned image.
          --source FlatBed|Automatic Document Feeder [Automatic Document Feeder]
              Selects the scan source (such as a document-feeder).
          --brightness -50..50% (in steps of 1) [inactive]
              Controls the brightness of the acquired image.
          --contrast -50..50% (in steps of 1) [inactive]
              Controls the contrast of the acquired image.
        Geometry:
          -l 0..215.9mm (in steps of 0.0999908) [0]
              Top-left x position of scan area.
          -t 0..355.6mm (in steps of 0.0999908) [0]
              Top-left y position of scan area.
          -x 0..215.9mm (in steps of 0.0999908) [215.88]
              Width of scan-area.
          -y 0..355.6mm (in steps of 0.0999908) [355.567]
              Height of scan-area.
      
      
      All options specific to device `brother2:bus1;dev1':
        Mode:
          --mode Black & White|Gray[Error Diffusion]|True Gray|24bit Color|24bit Color[Fast] [24bit Color]
              Select the scan mode
          --resolution 100|150|200|300|400|600|1200|2400|4800|9600dpi [200]
              Sets the resolution of the scanned image.
          --source FlatBed|Automatic Document Feeder [Automatic Document Feeder]
              Selects the scan source (such as a document-feeder).
          --brightness -50..50% (in steps of 1) [inactive]
              Controls the brightness of the acquired image.
          --contrast -50..50% (in steps of 1) [inactive]
              Controls the contrast of the acquired image.
        Geometry:
          -l 0..215.9mm (in steps of 0.0999908) [0]
              Top-left x position of scan area.
          -t 0..355.6mm (in steps of 0.0999908) [0]
              Top-left y position of scan area.
          -x 0..215.9mm (in steps of 0.0999908) [215.88]
              Width of scan-area.
          -y 0..355.6mm (in steps of 0.0999908) [355.567]
              Height of scan-area.
      

      ausserdem habe ich noch gefunden: https://en.opensuse.org/SDB:Configuring_Scanners#Frontend

      prosit

      seth

      1. Oh! Danke!

  3. Moin :)

    Ich helfe gerne soweit ich kann.

    campingrider@WISHMASTERSCAVE:~$ php ./scanner.php 
    -----------------------------------------------------------
        --format=pnm|tiff|png|jpeg  file format of output file
        --batch-count=#        how many pages to scan in batch mode
        --batch-increment=#    increase page number in filename by #
        --batch-double         increment page number by two, same as
                               --batch-increment=2
        --batch-print          print image filenames to stdout
        --batch-prompt         ask for pressing a key before scanning a page
        --accept-md5-only      only accept authorization requests using md5
        --mode Lineart|Gray|Color [Lineart]
        --depth 8bit [inactive]
        --halftoning None|Halftone A (Hard Tone)|Halftone B (Soft Tone)|Halftone C (Net Screen)|Dither A (4x4 Bayer)|Dither B (4x4 Spiral)|Dither C (4x4 Net Screen)|Dither D (8x4 Net Screen)|Text Enhanced Technology|Download pattern A|Download pattern B [inactive]
        --dropout None|Red|Green|Blue [None]
        --brightness 0..0 [inactive]
        --sharpness -2..2 [inactive]
        --gamma-correction User defined (Gamma=1.0)|User defined (Gamma=1.8) [User defined (Gamma=1.8)]
        --color-correction None|Built in CCT profile|User defined CCT profile [inactive]
        --resolution 75|100|150|300|600|1200dpi [75]
        --threshold 0..255 [128]
        --mirror[=(yes|no)] [inactive]
        --auto-area-segmentation[=(yes|no)] [inactive]
        --red-gamma-table 0..255,...
        --green-gamma-table 0..255,...
        --blue-gamma-table 0..255,...
        --wait-for-button[=(yes|no)] [no]
        --cct-type Automatic|Reflective|Colour negatives|Monochrome negatives|Colour positives [inactive]
        --cct-profile -2..2,...
        --preview[=(yes|no)] [no]
        -l 0..215.9mm [0]
        -t 0..297.18mm [0]
        -x 0..215.9mm [215.9]
        -y 0..297.18mm [297.18]
        --source Flatbed [inactive]
        --auto-eject[=(yes|no)] [inactive]
        --film-type Positive Film|Negative Film|Positive Slide|Negative Slide [inactive]
        --focus-position Focus on glass|Focus 2.5mm above glass [inactive]
        --bay 1|2|3|4|5|6 [inactive]
        --eject [inactive]
        --adf-mode Simplex|Duplex [inactive]
    All options specific to device `epson2:net:192.168.178.21':
        --mode Lineart|Gray|Color [Lineart]
        --depth 8bit [inactive]
        --halftoning None|Halftone A (Hard Tone)|Halftone B (Soft Tone)|Halftone C (Net Screen)|Dither A (4x4 Bayer)|Dither B (4x4 Spiral)|Dither C (4x4 Net Screen)|Dither D (8x4 Net Screen)|Text Enhanced Technology|Download pattern A|Download pattern B [inactive]
        --dropout None|Red|Green|Blue [None]
        --brightness 0..0 [inactive]
        --sharpness -2..2 [inactive]
        --gamma-correction User defined (Gamma=1.0)|User defined (Gamma=1.8) [User defined (Gamma=1.8)]
        --color-correction None|Built in CCT profile|User defined CCT profile [inactive]
        --resolution 75|100|150|300|600|1200dpi [75]
        --threshold 0..255 [128]
        --mirror[=(yes|no)] [inactive]
        --auto-area-segmentation[=(yes|no)] [inactive]
        --red-gamma-table 0..255,...
        --green-gamma-table 0..255,...
        --blue-gamma-table 0..255,...
        --wait-for-button[=(yes|no)] [no]
        --cct-type Automatic|Reflective|Colour negatives|Monochrome negatives|Colour positives [inactive]
        --cct-profile -2..2,...
        --preview[=(yes|no)] [no]
        -l 0..215.9mm [0]
        -t 0..297.18mm [0]
        -x 0..215.9mm [215.9]
        -y 0..297.18mm [297.18]
        --source Flatbed [inactive]
        --auto-eject[=(yes|no)] [inactive]
        --film-type Positive Film|Negative Film|Positive Slide|Negative Slide [inactive]
        --focus-position Focus on glass|Focus 2.5mm above glass [inactive]
        --bay 1|2|3|4|5|6 [inactive]
        --eject [inactive]
        --adf-mode Simplex|Duplex [inactive]
    
    -----------------------------------------------------------
    PHP Notice:  Unbekannte Option: 'depth' mit String '8bit [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'halftoning' mit String 'None|Halftone A (Hard Tone)|Halftone B (Soft Tone)|Halftone C (Net Screen)|Dither A (4x4 Bayer)|Dither B (4x4 Spiral)|Dither C (4x4 Net Screen)|Dither D (8x4 Net Screen)|Text Enhanced Technology|Download pattern A|Download pattern B [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'dropout' mit String 'None|Red|Green|Blue [None]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'brightness' mit String '0..0 [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'sharpness' mit String '-2..2 [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'gamma-correction' mit String 'User defined (Gamma=1.0)|User defined (Gamma=1.8) [User defined (Gamma=1.8)]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'color-correction' mit String 'None|Built in CCT profile|User defined CCT profile [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'threshold' mit String '0..255 [128]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'mirror[=(yes|no)]' mit String '[inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'auto-area-segmentation[=(yes|no)]' mit String '[inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'red-gamma-table' mit String '0..255,...' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'green-gamma-table' mit String '0..255,...' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'blue-gamma-table' mit String '0..255,...' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'wait-for-button[=(yes|no)]' mit String '[no]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'cct-type' mit String 'Automatic|Reflective|Colour negatives|Monochrome negatives|Colour positives [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'cct-profile' mit String '-2..2,...' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'preview[=(yes|no)]' mit String '[no]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'auto-eject[=(yes|no)]' mit String '[inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'film-type' mit String 'Positive Film|Negative Film|Positive Slide|Negative Slide [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'focus-position' mit String 'Focus on glass|Focus 2.5mm above glass [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'bay' mit String '1|2|3|4|5|6 [inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'eject' mit String '[inactive]' in /home/campingrider/scanner.php on line 61
    PHP Notice:  Unbekannte Option: 'adf-mode' mit String 'Simplex|Duplex [inactive]' in /home/campingrider/scanner.php on line 61
    allScanners Object
    (
        [scanners] => Array
            (
                [epson2:net:192.168.178.21] => Array
                    (
                        [name] => Epson PID 0864 flatbed
                        [options] => Array
                            (
                                [mode] => Array
                                    (
                                        [type] => ValueList
                                        [default] => Lineart
                                        [options] => Array
                                            (
                                                [0] => Lineart
                                                [1] => Gray
                                                [2] => Color
                                            )
    
                                    )
    
                                [resolution] => Array
                                    (
                                        [type] => ValueList
                                        [default] => 75
                                        [options] => Array
                                            (
                                                [0] => 75
                                                [1] => 100
                                                [2] => 150
                                                [3] => 300
                                                [4] => 600
                                                [5] => 1200
                                            )
    
                                    )
    
                                [l] => Array
                                    (
                                        [min] => 0
                                        [max] => 215.9
                                        [type] => FromTo
                                        [default] => 0
                                    )
    
                                [t] => Array
                                    (
                                        [min] => 0
                                        [max] => 297.18
                                        [type] => FromTo
                                        [default] => 0
                                    )
    
                                [x] => Array
                                    (
                                        [min] => 0
                                        [max] => 215.9
                                        [type] => FromTo
                                        [default] => 0
                                    )
    
                                [y] => Array
                                    (
                                        [min] => 0
                                        [max] => 297.18
                                        [type] => FromTo
                                        [default] => 0
                                    )
    
                                [source] => Array
                                    (
                                        [type] => ValueList
                                        [default] => inactive
                                        [options] => Array
                                            (
                                                [0] => Flatbed
                                            )
    
                                    )
    
                            )
    
                    )
    
            )
    
    )
    
    

    Es handelt sich um ein Multifunktionsgerät mit Kennung EPSON Stylus SX420W, angeschlossen über dessen WLAN-Schnittstelle.

    Grüße,

    RIDER

    --
    Camping_RIDER a.k.a. Riders Flame a.k.a. Janosch Albers-Zoller
    # Twitter # Steam # YouTube # Self-Wiki # Selfcode: sh:) fo:) ch:| rl:) br:^ n4:? ie:% mo:| va:) js:) de:> zu:} fl:( ss:) ls:[
    1. Das ist ja “fett Futter“.