Skip to content

Commit

Permalink
Merge pull request #830 from onfido/spike/live-doc-capture-in-jpeg-fo…
Browse files Browse the repository at this point in the history
…rmat

Live doc image capture in JPEG format
  • Loading branch information
Kimmi Gan authored Oct 29, 2019
2 parents 369707d + 5626b95 commit 17407d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Photo/DocumentLiveCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class DocumentLiveCapture extends Component<Props, State> {
captureDocumentPhoto = () => {
this.setState({ isLoading: true })
sendEvent('Taking live photo of document')
screenshot(this.webcam, this.captureDocument)
screenshot(this.webcam, this.captureDocument, 'image/jpeg')
}

componentWillUnmount() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/utils/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ const base64toBlob = (image) => {
return new Blob([base64Data.integerArray], {type: base64Data.mimeString})
}

export const canvasToBlob = (canvas, callback) => {
export const canvasToBlob = (canvas, callback, mimeType = 'image/png') => {
if (!HTMLCanvasElement.prototype.toBlob) {
// Handle browsers that do not support canvas.toBlob() like Edge
const dataUrlImg = canvas.toDataURL()
return callback(base64toBlob(dataUrlImg))
}
return canvas.toBlob(callback, "image/png")
return canvas.toBlob(callback, mimeType)
}

const toDataUrl = type => (canvas, callback) => callback(canvas.toDataURL(type))
Expand Down
4 changes: 2 additions & 2 deletions src/components/utils/camera.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { canvasToBlob } from './blob'

export const screenshot = (webcam, callback) => {
export const screenshot = (webcam, callback, mimeType) => {
const canvas = webcam && webcam.getCanvas()
if (!canvas) {
console.error('webcam canvas is null')
return
}
const sdkMetadata = getDeviceInfo(webcam.stream)
canvasToBlob(canvas, blob => callback(blob, sdkMetadata))
canvasToBlob(canvas, blob => callback(blob, sdkMetadata), mimeType)
}

export const getRecordedVideo = (webcam, callback) => {
Expand Down

0 comments on commit 17407d6

Please sign in to comment.