Working with Images¶
Each document will contain one or more images. Each image represents a page or side of the document, for example, the front and back of a driving licence.
Document.Images
provides a list of all the images for the given document.
The Document()
class’s property Document.Images
provides a list of all images that are associated with the document.
Note
An instance of Image()
represents the metadata of a document
image and does not represent the image data itself. The binary image data
must be retrieved by separate means as described in Retrieving Image Data.
Image Metadata¶
The following example shows how to download the data for a document and access the image metadata:
Request
POST {{server}}/VPE/dataAccess/retrieveDocumentContainer/
Content-Type: application/json
{
"DeviceId": "device-id",
"SessionId": "...",
"ContainerId": "..."
}
Response
{
"Success": true,
"Message": "Operation executed successfully.",
"AccessDenied": false,
"SessionExpired": false,
"Container":
{
"Documents": [
{
"Images": [{
"CreatedAt": {...},
"CropArea": {
BottomLeft: {x: 0, y: 0},
BottomRight: {x: 0, y: 0},
TopLeft: {x: 0, y: 0},
TopRight: {x: 0, y: 0}
},
"DocumentId": "...",
"FileType": 1,
"Id": "...",
"ImageSourceId": null,
"ImageType": 2,
"Rotation": 0
}],
}]
}
}
Use the Document.Images
property to access image metadata.
var api = new TVS.Api();
api.login('username', 'password').then(function() {
// retrieve document container for the given containerId(guid)...
return api.retrieveDocumentContainer(containerId);
}).then(function(application) {
console.log('Document Images:');
for (var i = 0; i < application.Documents.length; i++) {
var documentImages = application.Documents[i].Images;
for (var j = 0; j < documentImages.length; j++) {
// represents the type of the document image.
console.log(
'document image:',
documentImages[j].getImageByType(imageType)
);
}
}
});
Use the Document.Images
property of the
Document()
class to access image metadata.
Image Types¶
The TrustID Javascript API distinguishes different types of images. The main image types are as follows:
Image.IMAGE_TYPE_DOCUMENT
- white-light entire document.Image.IMAGE_TYPE_DOCUMENTBACK
- white light entire document (backside, Non-MRZ).
The metadata for an image of a specific image type can be obtained using the helper method as part of the document object as shown here:
var api = new TVS.Api();
api.login('username', 'password').then(function() {
// retrieve document container for the given containerId(guid)...
return api.retrieveDocumentContainer(containerId);
}).then(function(application) {
// examine first document in application
var doc = application.Documents[0];
var img = doc.getImageByType(Image.IMAGE_TYPE_DOCUMENT);
if (img) {
console.log('full document image (white light):', img.getImageTypeDisplay(), img.Id);
} else {
console.log('document does not have metadata of a full white light document image');
}
});
Note
The actual binary image data can be retrieved from the TrustID Cloud separately - for example, to present an image to an operator. See Retrieving Image Data for more information.