UPC-E

UPC-E barcode in PHP: six digit compressed input, code examples and SVG output

Six digits instead of twelve, for packages too small to carry UPC-A. The compression works by suppressing runs of zeros in the manufacturer and product fields, so only UPC-A codes with the right zero pattern have a UPC-E form at all.

A code with no UPC-E form is rejected at encode time, before it reaches a label.

Type Token

ItemValue
Type tokenUPCE
Enum caseBarcodeType::UPCE
FamilyLinear
StandardISO/IEC 15420, GS1 General Specifications
Class\Com\Tecnick\Barcode\Type\Linear\UpcE

Input

ItemValue
Character setdigits, plus + to introduce an add-on
Length6 digits, or the 8 or 12 digit form it expands to
Checkcomputed from the expanded UPC-A form
Extra parametersnone

Examples

A compressed product code

<?php

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

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

echo $bobj->getInlineSvgCode();

UPC-E barcode encoding 725277

With a two-digit add-on

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

UPC-E barcode encoding 725277+12

Errors

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

PayloadMessage
1234567The code cannot be represented as a UPC-E symbol: 1234567
123456789The code cannot be represented as a UPC-E symbol: 123456789

See Also