EAN-13

EAN-13 barcode in PHP: 13 digit input, check digit, add-on symbols, code examples and SVG output

The thirteen-digit article number printed on retail packaging almost everywhere outside North America. The first digits are the GS1 company prefix, issued by a GS1 member organisation; the last is a modulo 10 check digit.

Give the library twelve digits and it computes the check. Give it thirteen and it verifies the one you supplied, rather than appending a second.

Type Token

ItemValue
Type tokenEAN13
Enum caseBarcodeType::EAN13
FamilyLinear
StandardISO/IEC 15420, GS1 General Specifications
Class\Com\Tecnick\Barcode\Type\Linear\EanOneThree

Input

ItemValue
Character setdigits, plus + to introduce an add-on
Length12 digits, or 13 with a valid check digit
Checkmodulo 10, appended when the payload is 12 digits and verified when it is 13
Extra parametersnone

Examples

An article number

<?php

require_once __DIR__ . '/vendor/autoload.php';

$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(
    type: 'EAN13',
    code: '9781234567897',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

echo $bobj->getInlineSvgCode();

EAN-13 barcode encoding 9781234567897

With a five-digit add-on

$bobj = $barcode->getBarcodeObj(
    type: 'EAN13',
    code: '9781234567897+12345',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

EAN-13 barcode encoding 9781234567897+12345

Errors

These payloads raise \Com\Tecnick\Barcode\Exception:

PayloadMessage
12345678901AInput code must be a number
0123456789013Invalid check digit: 2
9781234567897+123The add-on must be 2 or 5 digits: 123

See Also