Skip to content

Instantly share code, notes, and snippets.

@m3l1nd4
Last active April 1, 2021 04:43
Show Gist options
  • Save m3l1nd4/cb74163e2c0b3562e9b3cd27170d5c81 to your computer and use it in GitHub Desktop.
Save m3l1nd4/cb74163e2c0b3562e9b3cd27170d5c81 to your computer and use it in GitHub Desktop.
// Set options for camera
function setOptions(srcType) {
const options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: false,
correctOrientation: true,
};
return options;
}
// Take picture with camera
function openCamera(selection) {
try{
const srcType = Camera.PictureSourceType.CAMERA;
const options = setOptions(srcType);
navigator.camera.getPicture(
function cameraSuccess(imageUrl) {
displayImage(imageUrl);
},
function cameraError(error) {
console.debug("Unable to take picture: " + error, "app");
},
options
);}
catch {
console.error("Something went wrong.");
}
}
function openFilePicker(selection) {
...
}
// Add picture to DOM
function displayImage(img) {
let image = document.getElementById("imageFile");
image.src = "data:image/jpeg;base64," + img;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment