Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active October 14, 2021 01:07
Show Gist options
  • Save symisc/12644eaa4276e1652acb0977753e3b07 to your computer and use it in GitHub Desktop.
Save symisc/12644eaa4276e1652acb0977753e3b07 to your computer and use it in GitHub Desktop.
Scan Indian Aadhar) ID card via the PixLab docscan API endpoint. Extract the user face and process all fields - https://pixlab.io/cmd?id=docscan
<?php
/*
* Usage sample of the 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 India, Malaysia, Singapore, etc., extract the user face and parse all 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 files.
#
# https://pixlab.io/cmd?id=docscan for additional information.
$idcard_link = 'https://buletinonline.net/v7/wp-content/uploads/2016/06/Mykad-penghuni-puan-Noraini-2.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://pixlab.io/dsahboard
/* Process */
$pix = new Pixlab($key);
if( !$pix->get('docscan',[
'img' => $idcard_link, # Passport scanned image
'type' => 'idcard', # Type of document we are going to scan
'country' => 'india' # from India, we support also Malaysia/Singapore/US and Passports,
]) ){
echo $pix->get_error_message()."\n";
die;
}
/* Output the scan result */
echo "User Cropped Face: " . $pix->json->face_url . "\n";
#echo "Raw Text: " . $pix->json->full_text . "\n";
echo "Fields:\n";
# At this stage, the face should be extracted and the array populated with the appropriate information.
if( isset($pix->json->fields->country) ) echo "Country: ".$pix->json->fields->country . "\n";
if( isset($pix->json->fields->id) ) echo "ID: ".$pix->json->fields->id . "\n";
if( isset($pix->json->fields->name) ) echo "Name: ".$pix->json->fields->name . "\n";
if( isset($pix->json->fields->address) ) echo "Address: ".$pix->json->fields->address . "\n";
if( isset($pix->json->fields->sex) ) echo "Sex: ".$pix->json->fields->sex . "\n";
if( isset($pix->json->fields->birth) ) echo "Date of birth: ".$pix->json->fields->birth . "\n";
?>
@symisc
Copy link
Author

symisc commented Mar 11, 2020

Scan an ID card using the PixLab /docscan API endpoint.

Given a government issued ID card from India, Malaysia, Singapore, etc., extract the user face and parse all fields.

PixLab recommend that you connect your AWS S3 bucket via your dashboard at https://pixlab.io/dashboard
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 files.

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

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