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 @@
.push(function () {
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) {
......@@ -528,7 +552,9 @@
gadget.element.querySelector('video').srcObject.getVideoTracks()[0]
),
original_blob_url,
blob_url;
blob_url,
original_width,
original_height;
return new RSVP.Queue()
.push(function () {
......@@ -537,9 +563,12 @@
return image_capture.getPhotoCapabilities();
})
.push(function (capabilities) {
original_width = capabilities.imageWidth.max;
original_height = capabilities.imageHeight.max;
return image_capture.takePhoto({
imageWidth: capabilities.imageWidth.max,
imageHeight: capabilities.imageHeight.max
imageWidth: original_width,
imageHeight: original_height
});
})
.push(function (blob) {
......@@ -551,6 +580,9 @@
div = gadget.element.querySelector(".camera-input");
div.replaceChild(img, div.firstElementChild);
return resizePhoto(blob, original_width, original_height);
})
.push(function (blob) {
return fixPhotoOrientation(blob);
})
.push(function (blob) {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.58248.12377.39526</string> </value>
<value> <string>982.58327.23330.31351</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1585644055.38</float>
<float>1585648785.07</float>
<string>UTC</string>
</tuple>
</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