From 64be9edeac7deeb15e3dddef24979c079b743506 Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Thu, 3 Sep 2020 12:17:32 -0400 Subject: [PATCH] adjusted size factor based on camera resolution added additional check so that tests pass updates for requested changes --- src/id-verification/Camera.jsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/id-verification/Camera.jsx b/src/id-verification/Camera.jsx index be73833..be6a4b1 100644 --- a/src/id-verification/Camera.jsx +++ b/src/id-verification/Camera.jsx @@ -129,8 +129,9 @@ class Camera extends React.Component { if (this.state.dataUri) { return this.reset(); } + const config = { - sizeFactor: 1, + sizeFactor: this.getSizeFactor(), }; this.playShutterClick(); @@ -139,6 +140,27 @@ class Camera extends React.Component { this.props.onImageCapture(dataUri); } + getSizeFactor() { + let sizeFactor = 1; + const settings = this.cameraPhoto.getCameraSettings(); + if (settings) { + const videoWidth = settings.width; + const videoHeight = settings.height; + // need to multiply by 3 because each pixel contains 3 bytes + const currentSize = videoWidth * videoHeight * 3; + // chose a limit of 9,999,999 (bytes) so that result will + // always be less than 10MB + const ratio = 9999999 / currentSize; + + // if the current resolution creates an image larger than 10 MB, adjust sizeFactor (resolution) + // to ensure that image will have a file size of less than 10 MB. + if (ratio < 1) { + sizeFactor = ratio; + } + } + return sizeFactor; + } + playShutterClick() { const audio = new Audio(`data:audio/mp3;base64,${shutter.base64}`); audio.play();