MRZ Parser — Extract machine-readable info from Passport, Visa, and Travel Documents.

Rakibul Islam
2 min readJun 29, 2022

--

Machine Readable Passport

MRZ Parser is a PHP package to extract machine-readable information from passports, visas, and two types of travel documents (TD1, TD2). Basically, MRZ contains specifications of the document type, name, document number, nationality, date of birth, sex, document expiration date, etc.

Installation:

You may use Composer to install the MRZ parser on your PHP project:

composer require rakibdevs/mrz-parser

Usage:

Output:

{
"type": "Passport",
"card_no": "L898902C3",
"issuer": "Utopian",
"date_of_expiry": "2012-04-15",
"first_name": "ANNA MARIA",
"last_name": "ERIKSSON",
"date_of_birth": "1974-08-12",
"gender": "Female",
"personal_number": "ZE184226B",
"nationality": "Utopian"
}

Supported Document:

  1. Passport
  2. Visa
  3. Travel Document (TD1)
  4. Travel Document (TD2)

Passport: This is a TD3 type document Passport MRZ consists of 2 rows of 44 characters each and should start with P. Allowed characters are A–Z, 0–9, and the filler character <. Example of a passport MRZ,

P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
L898902C36UTO7408122F1204159ZE184226B<<<<<10

Visa: There are two types of visa documents that are described in ICAO Document 9303. MRV-A and MRV-B.

MRV-A (Machine Readable Visa type A) consists of 2 rows of 44 characters each and should start with V. Example,

V<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
L8988901C4XXX7408122F96121096ZE184226B<<<<<<

Output:

{
"type": "Visa",
"card_no": "L8988901C",
"issuer": "Utopian",
"date_of_expiry": "1996-12-10",
"first_name": "ANNA MARIA",
"last_name": "ERIKSSON",
"date_of_birth": "1974-08-12",
"gender": "Female",
"nationality": "Unspecified Nationality \/ Unknown"
}

MRV-B (Machine Readable Visa type B) consists of 2 rows of 36 characters each and should start with V. Example,

V<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<
L8988901C4XXX7408122F9612109<<<<<<<<

Travel Document: Crew Member Certificates, nationally issued ID cards, and passport cards will be TD1 or TD2 size defined by ISO/IEC 7810.

TD1 consists of 3 rows of 30 characters each and should start with I, A or C. Example,

I<UTOD231458907<<<<<<<<<<<<<<<
7408122F1204159UTO<<<<<<<<<<<6
ERIKSSON<<ANNA<MARIA<<<<<<<<<<

TD2 consists of 2 rows of 36 characters each and should start with I, A or C. Example,

I<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<
D231458907UTO7408122F1204159<<<<<<<6

To extract MRZ from this card image, you may use Google Vision API or similar APIs that extract OCR from image.

For more details, visit Github. You can also see the article in detail Machine-readable passport on Wikipedia.

Thanks for reading.

--

--

Rakibul Islam
Rakibul Islam

Written by Rakibul Islam

Passionate PHP Expert, Love to make things that make a difference! You can find me here, https://www.linkedin.com/in/rakibhstu/

No responses yet