GM-Script-Writer-62850 / PHP-Scanner-Server

Allows you to use your Linux install as a web based scanner server thus allowing you to scan with any web enabled device; Now supports server side printing! (As of 1.4.11)
59 stars 17 forks source link

PHP Scanner Server is correctly working when no region, but breaks if region is selected #33

Open wsfreund opened 8 years ago

wsfreund commented 8 years ago

Hi there,

I'm very happy to have found this git package. I've installed it on my Rpi 2, and it is successfully working when I try to scan a file. A sample log file when I don't select any region is as follows:

www-data@:/var/www/scanner$ lsusb -d '04b8:0849' # See Bug #13
Bus 001 Device 005: ID 04b8:0849 Seiko Epson Corp. Stylus SX205
www-data@:/var/www/scanner$ scanimage -d 'epson2:libusb:001:005' -l 0 -t 0 -x 215.9 -y 297.18 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'
The output of this command unfortunately has to be suppressed to prevent errors :(
Run `sudo -u www-data scanimage -d 'epson2:libusb:001:005' -l 0 -t 0 -x 215.9 -y 297.18 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'` for output info
www-data@:/var/www/scanner$ convert '/tmp/scandir0/scan_file0.pnm' -scale '450x471' 'scans/thumb/Preview_0_Dec_29_2015~18-19-34.jpg'

www-data@:/var/www/scanner$ convert '/tmp/scandir0/scan_file0.pnm' -alpha off 'scans/file/Scan_0_Dec_29_2015~18-19-34.png'

www-data@:/var/www/scanner$ 

But, if I select a region, it then fails to retrieve the region configuration:

www-data@:/var/www/scanner$ lsusb -d '04b8:0849' # See Bug #13
Bus 001 Device 005: ID 04b8:0849 Seiko Epson Corp. Stylus SX205
www-data@:/var/www/scanner$ scanimage -d 'epson2:libusb:001:005' -l 0 -t 0 -x 0 -y 0 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'
The output of this command unfortunately has to be suppressed to prevent errors :(
Run `sudo -u www-data scanimage -d 'epson2:libusb:001:005' -l 0 -t 0 -x 0 -y 0 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'` for output info
www-data@:/var/www/scanner$ echo 'Scan Failed...'
Scan Failed...
www-data@:/var/www/scanner$ echo 'Maybe this scanner does not report it size correctly, maybe the default scan size will work it may or may not be a full scan.'
Maybe this scanner does not report it size correctly, maybe the default scan size will work it may or may not be a full scan.
www-data@:/var/www/scanner$ echo 'If it is not a full scan you are welcome to manually edit your www-data@:/var/www/scanner/config/scanners.json file with the correct size.'
If it is not a full scan you are welcome to manually edit your www-data@:/var/www/scanner/config/scanners.json file with the correct size.
www-data@:/var/www/scanner$ echo 'Attempting to scan without forcing full scan'
Attempting to scan without forcing full scan
The output of this command unfortunately has to be suppressed to prevent errors :(
Run `sudo -u www-data echo 'Attempting to scan without forcing full scan'` for output info
www-data@:/var/www/scanner$ scanimage -d 'epson2:libusb:001:005' --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'
The output of this command unfortunately has to be suppressed to prevent errors :(
Run `sudo -u www-data scanimage -d 'epson2:libusb:001:005' --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'` for output info
www-data@:/var/www/scanner$ convert '/tmp/scandir0/scan_file0.pnm' -scale '450x471' 'scans/thumb/Preview_0_Dec_29_2015~18-20-32.jpg'

www-data@:/var/www/scanner$ convert '/tmp/scandir0/scan_file0.pnm' -alpha off 'scans/file/Scan_0_Dec_29_2015~18-20-32.png'

www-data@:/var/www/scanner$ 

As it can be seen on the log, it uses a region of 0,0,0,0, although it was selected a region of 0,0,421,471 as can be seen in the image.

Screenshot

Any hint of what might be causing this?

wsfreund commented 8 years ago

I've just found out that the following variables on index.php seem to be causing the issue:

$M_WIDTH=Get_Values('loc_maxW'); $M_HEIGHT=Get_Values('loc_maxH');

They are set to '', so Get_Values function cannot retrieve loc_maxW and neither loc_maxH.

I've manually set them to the maximum width and height, but this makes it impossible to resize once again after first resize.

GM-Script-Writer-62850 commented 8 years ago

this is my output, same settings as screenshot

www-data@127.0.0.1:/home/www-data/php-scanner$ scanimage -d 'hpaio:/usb/Deskjet_F4400_series?serial=CN05DC61TP05C5' --source 'Flatbed' -l 0 -t 0 -x 201.98644444444 -y 279.4 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'
The output of this command unfortunately has to be suppressed to prevent errors :(
Run `sudo -u www-data scanimage -d 'hpaio:/usb/Deskjet_F4400_series?serial=CN05DC61TP05C5' --source 'Flatbed' -l 0 -t 0 -x 201.98644444444 -y 279.4 --resolution 75 --mode 'Color' --format=pnm > '/tmp/scandir0/scan_file0.pnm'` for output info
www-data@127.0.0.1:/home/www-data/php-scanner$ date +%z
-0500
www-data@127.0.0.1:/home/www-data/php-scanner$ echo "Warning, Guessing Time Zone:\n\tGuessed as GMT -5.\n\tdate.timezone is not set in your /etc/php5/apache2/php.ini file.\n\tIt is probably set on line 880.\n\tThere is also a override in /home/www-data/php-scanner/config.ini on line 11."
Warning, Guessing Time Zone:
    Guessed as GMT -5.
    date.timezone is not set in your /etc/php5/apache2/php.ini file.
    It is probably set on line 880.
    There is also a override in /home/www-data/php-scanner/config.ini on line 11.
www-data@127.0.0.1:/home/www-data/php-scanner$ convert '/tmp/scandir0/scan_file0.pnm' -scale '450x471' 'scans/thumb/Preview_0_Dec_29_2015~16-48-01.jpg'

I have encountered a scanner that reports it size wrong so if you were to manually tell it to run a full scan it fails to scan cause it is out of bounds, i would have to guess there is a issue which some code i don't recall writing to compensate for that but what does not make sense is the 1st attempt to scan used a 0,0,0,0 setting

can you post your scanners help data you can get that info from this page by clicking the device string http://10.0.1.15/scanner/index.php?page=Device%20Notes

wsfreund commented 8 years ago

Hi @GM-Script-Writer-62850, thanks a lot for your reply, sorry to let you waiting this long. The image you requested:

schnappschuss 2016-01-10 16 46 38

The 0,0,0,0 setting comes from the fact that M_WIDTH and M_HEIGHT are empty. When it does this calculations:

$WIDTH=$WIDTH/$M_WIDTH*$TRUE_W;
$HEIGHT=$HEIGHT/$M_HEIGHT*$TRUE_H;
$X=$X_1/$M_WIDTH*$TRUE_W;
$Y=$Y_1/$M_HEIGHT*$TRUE_H;
$SIZE_X=$WIDTH;
$SIZE_Y=$HEIGHT;

around line 1200, as they are unset, all values are set to 0.

Thanks for your help. :)

GM-Script-Writer-62850 commented 8 years ago

i need the terminal output shown when you click on the device string (2ed bullet point) this file would also help: /var/www/scanner/config/scanners.json (not necessary if i have the other)

wsfreund commented 8 years ago

The content from scanners.json:

pi@raspberrypi:/var/www/scanner $ cat  /var/www/scanner/config/scanners.json && echo
[{"ID":0,"INUSE":0,"DEVICE":"epson2:libusb:001:004","NAME":"Epson NX200 flatbed scanner","SOURCE":"Inactive","DPI-Inactive":"75|300|600|1200","DUPLEX-Inactive":false,"MODE-Inactive":"Lineart|Gray|Color","WIDTH-Inactive":215.9,"HEIGHT-Inactive":297.18,"UUID":"04b8:0849"}]

And the terminal output clicking on the second line:

All options specific to device `epson2:libusb:001:004':
  Scan Mode:
    --mode Lineart|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --depth 8 [inactive]
        Number of bits per sample, typical values are 1 for "line-art" and 8
        for multibit scans.
    --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]
        Selects the halftone.
    --dropout None|Red|Green|Blue [None]
        Selects the dropout.
    --brightness 0..0 [inactive]
        Selects the brightness.
    --sharpness -2..2 [inactive]

    --gamma-correction User defined (Gamma=1.0)|User defined (Gamma=1.8) [User defined (Gamma=1.8)]
        Selects the gamma correction value from a list of pre-defined devices
        or the user defined table, which can be downloaded to the scanner
    --color-correction None|Built in CCT profile|User defined CCT profile [inactive]
        Sets the color correction table for the selected output device.
    --resolution 75|300|600|1200dpi [75]
        Sets the resolution of the scanned image.
    --threshold 0..255 [128]
        Select minimum-brightness to get a white point
  Advanced:
    --mirror[=(yes|no)] [inactive]
        Mirror the image.
    --auto-area-segmentation[=(yes|no)] [inactive]
        Enables different dithering modes in image and text areas
    --red-gamma-table 0..255,...
        Gamma-correction table for the red band.
    --green-gamma-table 0..255,...
        Gamma-correction table for the green band.
    --blue-gamma-table 0..255,...
        Gamma-correction table for the blue band.
    --wait-for-button[=(yes|no)] [inactive]
        After sending the scan command, wait until the button on the scanner
        is pressed to actually start the scan process.
  Color correction:
    --cct-type Automatic|Reflective|Colour negatives|Monochrome negatives|Colour positives [inactive]
        Color correction profile type
    --cct-profile -2..2,...
        Color correction profile data
  Preview:
    --preview[=(yes|no)] [no]
        Request a preview-quality scan.
  Geometry:
    -l 0..215.9mm [0]
        Top-left x position of scan area.
    -t 0..297.18mm [0]
        Top-left y position of scan area.
    -x 0..215.9mm [215.9]
        Width of scan-area.
    -y 0..297.18mm [297.18]
        Height of scan-area.
  Optional equipment:
    --source Flatbed [inactive]
        Selects the scan source (such as a document-feeder).
    --auto-eject[=(yes|no)] [inactive]
        Eject document after scanning
    --film-type Positive Film|Negative Film|Positive Slide|Negative Slide [inactive]

    --focus-position Focus on glass|Focus 2.5mm above glass [inactive]
        Sets the focus position to either the glass or 2.5mm above the glass
    --bay 1|2|3|4|5|6 [inactive]
        Select bay to scan
    --eject [inactive]
        Eject the sheet in the ADF
    --adf-mode Simplex|Duplex [inactive]
        Selects the ADF mode (simplex/duplex)
GM-Script-Writer-62850 commented 8 years ago

Odd, seems to work here, at least generating the command to scan which is where the issue is manifesting for you i did find a error while i was checking for this issue (unrelated though)

maybe something very strange is happening, lets pop a debug message in here debugMsg("W='$WIDTH',H='$HEIGHT',MW='$M_WIDTH'");

that is right after line 1185 in index.php this SHOULD print a message of W='427',H='471',MW='450' when you run a scan with the settings from your screenshot you can pop another one after line 1238 in index.php

the second message should print W='204.86511111111',H='279.4',MW='450'

GM-Script-Writer-62850 commented 8 years ago

i'm wondering if the browser is passing all arguments when you run a scan like you did in that screenshot use the element inspector's network tab select index.php then click params on the right

the only thing that should be different is the scanner number (i added yours as 2 here, it is 0 for you)

wsfreund commented 8 years ago

I have followed your instructions. First I've reset the index.php to the head used on the github (I didn't reset all the package otherwise I would have to reconfigure the scanner, and I wanted to avoid this if possible).

After, I've added the debug messages on the places you requested. What follows are the images of the debug messages without selecting any region:

schnappschuss 2016-01-10 19 28 53

After selecting a region:

schnappschuss 2016-01-10 19 29 34

and the browser inspected parameters:

schnappschuss 2016-01-10 19 34 01

It seems that the browser, for some reason, is not passing the right loc_maxW and loc_maxH comparing to your sample.

I'll wait for more instruction as I don't know what could be the cause of this (I don't know any web language and how the browsers communicate).

GM-Script-Writer-62850 commented 8 years ago

those values come from the rendered size of the preview image, they are set when you click the scan button during right before it lets the page submit https://github.com/GM-Script-Writer-62850/PHP-Scanner-Server/blob/master/res/main.js#L110-L111 maybe there is a bug in the mac firefox? tried chrome or safari?

wsfreund commented 8 years ago

I've attempted in the two remaining browsers. It worked only on the chrome… really funny bug.

Safari: schnappschuss 2016-01-10 20 09 08

Chrome: schnappschuss 2016-01-10 20 14 34

Thanks a lot for helping me track this issue.

GM-Script-Writer-62850 commented 8 years ago

in firefox open the error console (CTRL+SHIFT+K) do you get a error when clicking submit in firefox?

wsfreund commented 8 years ago

It says: unreachable code after return statement main.js:742:1, but it is a warning. I've added all verbosity that I could and took a screenshot.

schnappschuss 2016-01-10 20 39 22