Commit e7f5674b authored by Romain Courteaud's avatar Romain Courteaud

erp5_document_scanner: resize photo if needed

Reduce the number of pixel managed by caman
parent 37c35b8c
...@@ -502,7 +502,31 @@ ...@@ -502,7 +502,31 @@
.push(function () { .push(function () {
return promiseCanvasToBlob(div.firstElementChild); return promiseCanvasToBlob(div.firstElementChild);
}); });
}
function resizePhoto(blob, original_width, original_height) {
var expected_width = 2000;
if (original_width < expected_width) {
return blob;
}
// expected_height = parseInt((original_height * expected_width) / original_width);
// alert(expected_width + ' ' + expected_height);
return new RSVP.Queue(createImageBitmap(blob, {
resizeWidth: expected_width,
// resizeHeight: expected_height,
resizeQuality: 'high'
}))
.push(function (bitmap) {
var canvas = domsugar('canvas');
canvas.width = bitmap.width;
canvas.height = bitmap.height;
canvas.getContext('2d').drawImage(bitmap, 0, 0);
return promiseCanvasToBlob(canvas);
});
} }
function createLoadedImgElement(url) { function createLoadedImgElement(url) {
...@@ -528,7 +552,9 @@ ...@@ -528,7 +552,9 @@
gadget.element.querySelector('video').srcObject.getVideoTracks()[0] gadget.element.querySelector('video').srcObject.getVideoTracks()[0]
), ),
original_blob_url, original_blob_url,
blob_url; blob_url,
original_width,
original_height;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -537,9 +563,12 @@ ...@@ -537,9 +563,12 @@
return image_capture.getPhotoCapabilities(); return image_capture.getPhotoCapabilities();
}) })
.push(function (capabilities) { .push(function (capabilities) {
original_width = capabilities.imageWidth.max;
original_height = capabilities.imageHeight.max;
return image_capture.takePhoto({ return image_capture.takePhoto({
imageWidth: capabilities.imageWidth.max, imageWidth: original_width,
imageHeight: capabilities.imageHeight.max imageHeight: original_height
}); });
}) })
.push(function (blob) { .push(function (blob) {
...@@ -551,6 +580,9 @@ ...@@ -551,6 +580,9 @@
div = gadget.element.querySelector(".camera-input"); div = gadget.element.querySelector(".camera-input");
div.replaceChild(img, div.firstElementChild); div.replaceChild(img, div.firstElementChild);
return resizePhoto(blob, original_width, original_height);
})
.push(function (blob) {
return fixPhotoOrientation(blob); return fixPhotoOrientation(blob);
}) })
.push(function (blob) { .push(function (blob) {
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.58248.12377.39526</string> </value> <value> <string>982.58327.23330.31351</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1585644055.38</float> <float>1585648785.07</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment