nextcloud-scanner
nextcloud-scanner copied to clipboard
Add ability to set scan size
Currently the scan size is hardcoded to A4 in the code. Users should be able to set the scan size, either with two fields for the X and Y axis respectively or a graphical selector screen (preferably from a preview scan) as suggested by @Biont.
I have already been toying around with this and made good progress with the rectangular selection from a preview.
The only thing I'm struggling with is the inability to tell what resolution the preview will be delivered in.
It seems that all scanning parameters are entirely provided and handled by the individual backend. There is no hard contract about what parameters exist and how they are handled. For example, some backends seem to have a --preview
option but mine doesn't. And secondly, some scanners accept any resolution while mine provides only a few, 75 being the lowest.
I need this value to determine the size of scanning area and to calculate the selected area. My current idea is to try and read the resolution from the metadata of the scanned file as there does not appear to be a uniform way of receiving the capabilities of the current scanner before scanning the preview.
Progress! I now determine the available scanning resolutions via scanimage -A
and then perform some string functions to get a list of supported resolutions OR the min/max resolution of the supported range.
Based on this, I determine the resolution closest to my desired resolution of 30 and send it back to the frontend together with the base64'd preview image.
This allows me to calculate the needed offsets in millimetres:
Now it's only a matter of reading out the fields and passing them to the final scanimage
call that creates the new file.
As a side note: Since I need to fetch supported resolutions from the sane backend anyway, it would make sense to also send them to the scan dialog so you can set your resolution based on what's actually available. We currently just make a wish and hope for the best.
So this went a little out of hand....
I was pretty much finished with implementing cropper.js and all I wanted to add was a "preview preview" that would allow changing scan geometry even before the preview was fetched and displayed. Depending on the scanner and available parameters, generating a preview can still take ~10s or something. So I wanted to display something while waiting for the preview and maybe make the preview optional entirely: If all you want is to scan a DIN A4 page and you know you've inserted it right, why wait for a preview at all? All it would take would be proper default values and maybe a preview image that has guidelines for basic letter types.
But for this to work, I would need to know the size of the scan bed and dynamically represent it inside the templates. This was made impossible by the astoundingly rudimentary functionality of ocTemplate
. It basically only allows variable interpolation and nothing else.
So I looked around for ways to make the dialog box a bit more dynamic and found that NC seems to encourage moving to vue.js and I looked at that.
I fiddled around a bit with the SANE-backend-params that I've already been able to send to the frontend and a little while later, I came up with this:
The other inputs are all functional as well and I can make scans that correspond to what I've set in the dialog.
This is now almost a complete rewrite of the app, so I hope you're still with me on this, @e-alfred It needs some more polishing, but I should be able to PR soon.
PS: This also contains almost everything needed to talk to multiple backends. My vision is that you simply select it from a dropdown right in the popup and maybe have a way to persist a default backend somewhere..
Has this been integrated in the app 0.2.3 because i do not have this ability (and i would love to have it)> Or is this only available for certain scanners?