Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active October 14, 2021 01:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save symisc/24a2315304dedc02d158e74451c45b31 to your computer and use it in GitHub Desktop.
Save symisc/24a2315304dedc02d158e74451c45b31 to your computer and use it in GitHub Desktop.
Scan an UAE (United Arab Emirates) ID card via the PixLab docscan API endpoint (PHP code sample). Extract the holder's face and display all fields - https://pixlab.io/cmd?id=docscan
<?php
/*
* Usage sample of the UAE ID card scanner API endpoint from PixLab - https://pixlab.io/cmd?id=docscan.
*/
/*
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github
* https://github.com/symisc/pixlab-php
*/
require_once "pixlab.php";
# Given a government issued ID card from the UAE (emirates). Extract the holder's face and display all scanned fields.
#
# PixLab recommend that you connect your AWS S3 bucket via your dashboard at https://console.pixlab.io/
# so that any cropped face or MRZ crop is stored automatically on your S3 bucket rather than the PixLab one.
# This feature should give you full control over your analyzed media assets.
#
# https://pixlab.io/cmd?id=docscan&&country=uae for additional information.
$idcard_link = 'https://pixlab.xyz/images/pixlab-uae-id.jpg'; # ID card prototype: Of course, replace with a real government issued id
$key = 'PIXLAB_API_KEY'; # Your PixLab API key that you can fetch from https://console.pixlab.io
# Start the scan Process
$pix = new Pixlab($key);
if( !$pix->get('docscan',[
'img' => $idcard_link, # UAE ID Card Input image (https://pixlab.xyz/images/pixlab-uae-id.jpg). POST method for direct upload is also supported
'type' => 'idcard', # Type of document we are going to scan
'country' => 'uae' # from the Emirates, we support also Malaysia/India/Singapore/US and Passports,
]) ){
echo $pix->get_error_message()."\n";
die;
}
# Output the scan result
echo "ID Card Holder's Face: " . $pix->json->face_url . "\n";
echo "Scanned Card Fields:\n";
# At this stage, the face should be extracted and the JSON object populated with the appropriate information.
if( isset($pix->json->fields->issuingCountry) ) echo "Issuing Country: ".$pix->json->fields->issuingCountry . "\n";
if( isset($pix->json->fields->documentNumber) ) echo "Document Number : ".$pix->json->fields->documentNumber . "\n";
if( isset($pix->json->fields->fullName) ) echo "Holder Full Name: ".$pix->json->fields->fullName . "\n";
if( isset($pix->json->fields->nationality) ) echo "Holder's Nationality: ".$pix->json->fields->nationality . "\n";
@symisc
Copy link
Author

symisc commented Oct 14, 2021

Given a government issued ID card from the UAE (emirates). Extract the holder's face and display all scanned fields.

PixLab recommend that you connect your AWS S3 bucket via your dashboard at https://console.pixlab.io/ so that any cropped face or MRZ crop is stored automatically on your S3 bucket rather than the PixLab one. his feature should give you full control over your analyzed media assets.

https://pixlab.io/cmd?id=docscan&&country=uae for additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment