Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active June 14, 2022 02:47
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/f35dac8baf170982c26fd76b7b593b09 to your computer and use it in GitHub Desktop.
Save symisc/f35dac8baf170982c26fd76b7b593b09 to your computer and use it in GitHub Desktop.
Scan a US Driving License image document from any of the U.S 50 states via the PixLab /docscan API endpoint. Crop the user's face and extract all fields - https://pixlab.io/cmd?id=docscan&type=usdl
<?php
/*
* Usage sample of the US Driver's License 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 submitted/uploaded, US Driver License image document from any of the 50 US state
# crop the license holder face, and extract all document fields (see below) ready to be consumed by your application.
#
# PixLab recommend that you connect your AWS S3 bucket via the dashboard at https://console.pixlab.io/
# so that any extracted face is automatically stored 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&type=usdl for additional information.
$us_driver_license_sample_link = 'https://www.aulicense.com/wp-content/uploads/2020/12/USA-DRIVERS-LICENSE.jpg';
$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' => $us_driver_license_sample_link, # US Driver license input image
'type' => 'usdl' # Type of document we are a going to scan, hence US driver license
]) ){
echo $pix->get_error_message()."\n";
die;
}
# Consume the scan output
echo "License Holder Crooped Face: " . $pix->json->face_url . "\n";
echo "Extracted Fields:\n";
# At this stage, all license images fields should be extracted and the JSON object populated with the appropriate information.
echo "Issuing Country: ".$pix->json->fields->country . "\n";
echo "Issuing State: ".$pix->json->fields->issuingState . "\n";
echo "Issuing State Code: ".$pix->json->fields->issuingStateCode . "\n";
echo "Holder Full Name: ".$pix->json->fields->fullName . "\n";
echo "License Number: ".$pix->json->fields->licenseNumber . "\n";
echo "Holder's Address: ".$pix->json->fields->address . "\n";
echo "Date Of Birth: ".$pix->json->fields->dateOfBirth . "\n";
echo "issuing Date: ".$pix->json->fields->issuingDate . "\n";
echo "Date Of Expiry: ".$pix->json->fields->expiryDate . "\n";
echo "Gender: ".$pix->json->fields->gender . "\n";
@symisc
Copy link
Author

symisc commented May 15, 2022

Given a submitted/uploaded, US Driver License image document from any of the 50 US state, crop the license holder face, and extract all document fields ready to be consumed by your application.

PixLab recommend that you connect your AWS S3 bucket via the dashboard at https://console.pixlab.io/ so that any extracted face is automatically stored 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