NeutrinosPlatform / cordova-plugin-document-scanner

cordova plugin for document scan
https://www.neutrinos.co/
MIT License
84 stars 63 forks source link

Need control over file quality and size. #35

Closed humblecoder closed 5 years ago

humblecoder commented 6 years ago

Is there any way to control the size/quality of the scanned file? As it stands, I'm scanning multiple files back to back and with file sizes ranging from 3 to 6 MB apiece then attempting to merge and/or manipulate them after the fact I quickly run up against memory issues.

ChrisTomAlx commented 6 years ago

Hey @humblecoder

Sorry about the delayed response. Unfortunately at the present moment this is not possible. However it is a good suggestion to allow the plugin user to decide compression ratios, so I shall add it to the future enhancements list.

Here is a "hacky" way you might be able to handle this, I haven't tested it out myself but it just might work. Scan all the images first, save their uri's (which is basically their location on the phone) somewhere you can retrieve them at will. Compress each one separately (using another plugin maybe?) then manipulate them as you wish. It would be better still if all this ran in the background as a single process. I know it is extra work, but I can't think of a better solution in the short term other than going and changing the scan library's native code.

Cheers, Chris Neutrinos

humblecoder commented 6 years ago

Hi @ChrisTomAlx ,

Thanks for the reply. Yes, the package that I'm using is actually performing an intermediate compression/encoding adjustment, but it's running out of memory and crashing the app. 😔

I'll see if I can't find some other way.

Thanks

bendspoons commented 5 years ago

I "solved" this by adding a resizing/convert function right after the image was taken. But this probably wont resolve performance issues.

humblecoder commented 5 years ago

@bendspoons I've attempted that but I still run out of memory. What method(s) did you use?

@ChrisTomAlx is there any particular reason that the default file size is large in the first place?

ChrisTomAlx commented 5 years ago

The plugin just takes in the image as is. If this is an android only issue then you could try using the camera plugin to take low quality pics. Then use the gallery picker option of the scan plugin.. Remember iOS does not have the gallery picker option.

Cheers, Chris Neutrinos

humblecoder commented 5 years ago

Currently, I'm only testing in iOS. Any updates in this particular case, or any chance of the "feature" being added to the project roadmap? 🤔

ChrisTomAlx commented 5 years ago

Hey @ all. Finally got around to fixing the quality issue. From plugin version 4.1.0 onwards, you can now pass in quality property inside the options object. As shown here :- {quality : 1.0}.

As mentioned in the readme, 1.0 is the highest quality and 5.0 is the lowest quality. Any values not in this range will default to the highest quality of 1.0

Example :-

    scan.scanDoc(onSuccess, onFail, {sourceType : 1, fileName : "myfilename", quality : 2.5}); 
    // sourceType will by default take value 1 if no value is set | 0 for gallery | 1 for camera. 
    // fileName will take default value "image" if no value set. Supported only on 4.x.x plugin version

    function onSuccess(imageURI) {
        alert(imageURI);
        console.log(imageURI);
        //var image = document.getElementById('myImage');
        //image.src = imageURI; // For iOS, use image.src = imageURI + '?' + Date.now(); to solve issue 10 if unique fileName is not set.

    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }

Closing this issue as upgrading to plugin version 4.1.0 should solve all of the following related issues #35, #46 & #47. If there are any problems in your trials please raise a new issue.

Cheers and thank you for being patient, Chris Neutrinos