Merge pull request #317 from edx/alangsto/fix_camera_resolution
Added logic for adjusting image resolution
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user