sbs20 / scanservjs

SANE scanner nodejs web ui
https://sbs20.github.io/scanservjs/
GNU General Public License v2.0
762 stars 145 forks source link

Error With Scanimage Output (With Proposed Fix) - Dell C1765NF #417

Closed ad3m3r5 closed 2 years ago

ad3m3r5 commented 2 years ago

Describe the bug

I was not able to get scanning working over USB, while printing does. So, I configured airscan to work with the scanning portion of the printer. Using the scanner over the command line works completely fine. However, an error occurs when trying to scan or get a preview using scanservjs.

Configuration:

scanimage -L Output:

device 'airscan:w0:Dell C1765nf Color MFP' is a WSD Dell C1765nf Color MFP ip=[removed]

Scanservjs errors:

Preview: Mar 23 11:10:04 [hostname] server.js[38682]: [2022-03-23T15:10:04.446Z] ERROR (Http): Error: /usr/bin/scanimage -d 'airscan:w0:Dell C1765nf Color MFP' --mode 'Color' --source 'Flatbed' --resolution 100 -l 0 -t 0 -x 215.9 -y 296.9 --format 'tiff' --brightness 0 --contrast 0 > data/temp/~tmp-scan-0-0001.tif > data/preview/preview.tif exited with code: 1, stderr: scanimage: open of device airscan:w0:Dell C1765nf Color MFP failed: Invalid argument

Scan: Mar 23 11:30:44 TheWholePi server.js[39971]: [2022-03-23T15:30:44.488Z] ERROR (Http): Error: /usr/bin/convert 'data/temp/~tmp-scan-0-0001.tif' -scale 868 -background '#808080' -extent '868x1194-0-0' 'data/preview/preview.tif' exited with code: 1, stderr: convert: Not a TIFF or MDI file, bad magic number 20545 (0x5041). `data/temp/~tmp-scan-0-0001.tif' @ error/tiff.c/TIFFErrors/606.

What I believe is happening

I believe the stdout for the scanimage command is not the actual file itself, so a "redirect" (>) does not work, at least for this printer. Therefore, the scanimage command built in scanimage.js is just saving text output from scanimage as an image file, such as preview.tif.

Proposed Solution:

I did some testing with the -o flag for scanimage, and I believe I found a solution. With some minimal changes in scanimage.js, api.js, and request.js, I was able to switch to scanimage using the output flag, rather than a stdout redirect. I'll open a PR to reflect these changes.

sbs20 commented 2 years ago

Hi. Thanks for reporting. Are you able to share the log please?

Also, what happens if you manually run:

/usr/bin/scanimage -d 'airscan:w0:Dell C1765nf Color MFP' --mode 'Color' --source 'Flatbed' --resolution 100 -l 0 -t 0 -x 215.9 -y 296.9 --format 'tiff' --brightness 0 --contrast 0 > test.tif

Can you share the file it generates? (So just an empty scan is fine)

ad3m3r5 commented 2 years ago

Yep. After reverting my changes on my Pi, the preview is now not erroring, but it also doesn't produce an image. So it's still broken.

scanservjs.log

GitHub is erroring when trying to share the file - "We don't support that file type". I changed the extension to .txt for it to allow me to upload it.

[test.txt removed]

sbs20 commented 2 years ago

Weird. Looks like this: https://github.com/alexpevzner/sane-airscan/issues/164

The "TIF"/stdout contains log output.

I've removed the logs before and after the BLOB, saved, and can see the windows test page.

ad3m3r5 commented 2 years ago

Interesting.... On that note though, would it be better to just go ahead and use -o instead of a redirect? It seems more robust rather than relying on stdout to be perfect across all scanners/printers.

Also - I'm going to remove the above test "image" since you have it now