Introduction
The GS1-128 code is a normalization of the standards from GS1 based on the BCGcode128. This code is an international standard which provides a way to exchange data between producers and distributors. The GS1-128 must start with the function 1 (~F1). It can contain multiple identifiers, however it mustn't be larger than 48 characters, this limit excludes the mandatory character ~F1. In order to facilitate the reading, the identifiers are surrounded by parentheses in the label; those parentheses are not encoded in the barcode.
There are different ways to send the data of your barcode to the method parse(), for instance, the following code:
| Identifier | Content |
| 01 | 12345678912343 |
| 92 | 123 |
| 15 | 880422 |
(01)12345678912343(92)123(15)880422
can be encoded like this
- A formatted string:
parse('(01)12345678912343(92)123~F1(15)880422') - A non-formatted string:
parse('011234567891234392123~F115880422') - A simple formatted table:
parse(array('(01)12345678912343', '(92)123', '(15)880422')) - A simple mixed table:
parse(array('0112345678912343', '(92)123~F115880422')) - A double table containing couples (ID, CONTENT)
parse(array(array('01', '12345678912343'), array('92', '123'), array('15', '880422')))
* Note about ~F1: If you provide the data in a string, you have to provide a separator at the end of your identifier if this one doesn't cover the maximum and is not positioned at the end of the code.
If you didn't indicate the checksum in the data and it is mandatory, it will be automatically calculated.
ex: parse('011234567891234') will give you: (01)1234567891234 3
There are two standards for the GS1-128, the strict and legacy modes. In legacy mode, separators are added between each identifier. In strict mode, separators are added only if the content of your data doesn't cover the maximum allowed. In this mode, it is highly recommended to use the table C if you use only numbers in your barcode. The following example will help you to understand the difference between those two modes:
Legacy Mode:
(01) content with fixed size [Separator] (91) content with variable size
[Separator] (8020) content with variable size
Strict Mode:
(01) content with fixed size (91)content with variable size [Separator *]
(8020) content with variable size
* The identifier 91 must contain between 1 and 30 characters. If this one contains 30 characters, there is no separator added.
Identifiers list:
| Id | Name | Type | Size | Checksum |
| 00 | Serial Shipping Container Code (SSCC-18) | Numeric | 2 + 18 | yes |
| 01 | Shipping Container Code (SSC) | Numeric | 2 + 14 | yes |
| 02 | Number of containers | Numeric | 2 + 14 | yes |
| 10 | Batch Number | Alphanumeric | 2 + 1 to 20 | no |
| 11 | Production Date | Date | 2 + 6 | no |
| 12 | Due date | Date | 2 + 6 | no |
| 13 | Packaging Date | Date | 2 + 6 | no |
| 15 | Sell by Date (Quality Control) | Date | 2 + 6 | no |
| 17 | Expiration Date | Date | 2 + 6 | no |
| 20 | Product Variant | Numeric | 2 + 2 | no |
| 21 | Serial Number | Alphanumeric | 2 + 1 to 20 | no |
| 240 | Additional Product Identification | Alphanumeric | 3 + 1 to 30 | no |
| 241 | Customer part number | Alphanumeric | 3 + 1 to 30 | no |
| 250 | Second Serial Number | Alphanumeric | 3 + 1 to 30 | no |
| 251 | Reference to source entity | Alphanumeric | 3 + 1 to 30 | no |
| 253 | Global Document Type Identifier | Numeric | 3 + 14 to 30 | no |
| 254 | GLN Extension Component | 3 + 1 to 20 | no | |
| 30 | Quantity Each | Numeric | 2 + 1 to 8 | no |
| 310y | Product Net Weight in kg | Numeric | 4 + 6 | no |
| 311y | Product Length/1st Dimension, in meters | Numeric | 4 + 6 | no |
| 312y | Product Width/Diameter/2nd Dimension, in meters | Numeric | 4 + 6 | no |
| 313y | Product Depth/Thickness/3rd Dimension, in meters | Numeric | 4 + 6 | no |
| 314y | Product Area, in square meters | Numeric | 4 + 6 | no |
| 315y | Product Volume, in liters | Numeric | 4 + 6 | no |
| 316y | product Volume, in cubic meters | Numeric | 4 + 6 | no |
| 320y | Product Net Weight, in pounds | Numeric | 4 + 6 | no |
| 321y | Product Length/1st Dimension, in inches | Numeric | 4 + 6 | no |
| 322y | Product Length/1st Dimension, in feet | Numeric | 4 + 6 | no |
| 323y | Product Length/1st Dimension, in yards | Numeric | 4 + 6 | no |
| 324y | Product Width/Diameter/2nd Dimension, in inches | Numeric | 4 + 6 | no |
| 325y | Product Width/Diameter/2nd Dimension, in feet | Numeric | 4 + 6 | no |
| 326y | Product Width/Diameter/2nd Dimension, in yards | Numeric | 4 + 6 | no |
| 327y | Product Depth/Thickness/3rd Dimension, in inches | Numeric | 4 + 6 | no |
| 328y | Product Depth/Thickness/3rd Dimension, in feet | Numeric | 4 + 6 | no |
| 329y | Product Depth/Thickness/3rd Dimension, in yards | Numeric | 4 + 6 | no |
| 330y | Container Gross Weight (Kg) | Numeric | 4 + 6 | no |
| 331y | Container Length/1st Dimension (Meters) | Numeric | 4 + 6 | no |
| 332y | Container Width/Diameter/2nd Dimension (Meters) | Numeric | 4 + 6 | no |
| 333y | Container Depth/Thickness/3rd Dimension (Meters) | Numeric | 4 + 6 | no |
| 334y | Container Area (Square Meters) | Numeric | 4 + 6 | no |
| 335y | Container Gross Volume (Liters) | Numeric | 4 + 6 | no |
| 336y | Container Gross Volume (Cubic Meters) | Numeric | 4 + 6 | no |
| 337y | Kilograms per square meter | Numeric | 4 + 6 | no |
| 340y | Container Gross Weight (Pounds) | Numeric | 4 + 6 | no |
| 341y | Container Length/1st Dimension, in inches | Numeric | 4 + 6 | no |
| 342y | Container Length/1st Dimension, in feet | Numeric | 4 + 6 | no |
| 343y | Container Length/1st Dimension in, in yards | Numeric | 4 + 6 | no |
| 344y | Container Width/Diameter/2nd Dimension, in inches | Numeric | 4 + 6 | no |
| 345y | Container Width/Diameter/2nd Dimension, in feet | Numeric | 4 + 6 | no |
| 346y | Container Width/Diameter/2nd Dimension, in yards | Numeric | 4 + 6 | no |
| 347y | Container Depth/Thickness/Height/3rd Dimension, in inches | Numeric | 4 + 6 | no |
| 348y | Container Depth/Thickness/Height/3rd Dimension, in feet | Numeric | 4 + 6 | no |
| 349y | Container Depth/Thickness/Height/3rd Dimension, in yards | Numeric | 4 + 6 | no |
| 350y | Product Area (Square Inches) | Numeric | 4 + 6 | no |
| 351y | Product Area (Square Feet) | Numeric | 4 + 6 | no |
| 352y | Product Area (Square Yards) | Numeric | 4 + 6 | no |
| 353y | Container Area (Square Inches) | Numeric | 4 + 6 | no |
| 354y | Container Area (Square Feet) | Numeric | 4 + 6 | no |
| 355y | Container Area (Square Yards) | Numeric | 4 + 6 | no |
| 356y | Net Weight (Troy Ounces) | Numeric | 4 + 6 | no |
| 357y | Kilograms per square meter | Numeric | 4 + 6 | no |
| 360y | Product Volume (Quarts) | Numeric | 4 + 6 | no |
| 361y | Product Volume (Gallons) | Numeric | 4 + 6 | no |
| 362y | Container Gross Volume (Quarts) | Numeric | 4 + 6 | no |
| 363y | Container Gross Volume (Gallons) | Numeric | 4 + 6 | no |
| 364y | Product Volume (Cubic Inches) | Numeric | 4 + 6 | no |
| 365y | Product Volume (Cubic Feet) | Numeric | 4 + 6 | no |
| 366y | Product Volume (Cubic Yards) | Numeric | 4 + 6 | no |
| 367y | Container Gross Volume (Cubic Inches) | Numeric | 4 + 6 | no |
| 368y | Container Gross Volume (Cubic Feet) | Numeric | 4 + 6 | no |
| 369y | Container Gross Volume (Cubic Yards) | Numeric | 4 + 6 | no |
| 37 | Number of Units Contained | Numeric | 2 + 1 to 8 | no |
| 390y | Amount payable-single monetary area | Numeric | 4 + 1 to 15 | no |
| 391y | Amount payable with ISO currency code | Numeric | 4 + 4 to 18 | no |
| 392y | Amount payable for a Variable Measure Trade Item single monetary unit | Numeric | 4 + 1 to 15 | no |
| 393y | Amount payable for a Variable Measure Trade Item - with ISO currency code | Numeric | 4 + 4 to 18 | no |
| 400 | Customer Purchase Order Number | Alphanumeric | 3 + 1 to 30 | no |
| 401 | Consignment number | Alphanumeric | 3 + 1 to 30 | no |
| 402 | Shipment Identification Number | Numeric | 3 + 17 | no |
| 403 | Routing code | Alphanumeric | 3 + 1 to 30 | no |
| 410 | Ship To/Deliver To Location Code (EAN13 or DUNS code) | Numeric | 3 + 13 | yes |
| 411 | Bill To/Invoice Location Code (EAN13 or DUNS code) | Numeric | 3 + 13 | yes |
| 412 | Purchase From Location Code (EAN13 or DUNS code) | Numeric | 3 + 13 | yes |
| 413 | Ship for - deliver for - forward to EAN.UCC Global Location Number | Numeric | 3 + 13 | yes |
| 414 | Identification of a physical location EAN.UCC Global Location Number | Numeric | 3 + 13 | yes |
| 415 | EAN.UCC Global Location Number of the invoicing party | Numeric | 3 + 13 | yes |
| 420 | Ship To/Deliver To Postal Code (Single Postal Authority) | Alphanumeric | 3 + 1 to 20 | no |
| 421 | Ship To/Deliver To Postal Code (Multiple Postal Authority) | Alphanumeric | 3 + 4 to 12 | no |
| 422 | Country of origin of a trade item | Numeric | 3 + 3 | no |
| 423 | Country of Initial Processing | Numeric | 3 + 3 to 15 | no |
| 424 | Country of Processing | Numeric | 3 + 3 | no |
| 425 | Country of Disassembly | Numeric | 3 + 3 | no |
| 426 | Country Covering full Process Chain | Numeric | 3 + 3 | no |
| 7001 | NATO Stock Number (NSN) | Numeric | 4 + 13 | no |
| 7002 | UN/ECE Meat Carcasses and Cuts Classification | Alphanumeric | 4 + 1 to 30 | no |
| 7003 | Expiration Date and Time | Numeric | 4 + 10 to | no |
| 7004 | Active Potency | Numeric | 4 + 1 to 4 | no |
| 703s | Approval Number of Processor with ISO Country Code | Alphanumeric | 4 + 3 to 31 | no |
| 8001 | Roll Products - Width/Length/Core Diameter | Numeric | 4 + 14 | no |
| 8002 | Electronic Serial Number (ESN) for Cellular Phone | Alphanumeric | 4 + 1 to 20 | no |
| 8003 | UPC/EAN Number and Serial Number of Returnable Asset | Alphanumeric | 4 + 15 to 30 | no |
| 8004 | UPC/EAN Serial Identification | Alphanumeric | 4 + 1 to 30 | no |
| 8005 | Price per Unit of Measure | Numeric | 4 + 6 | no |
| 8006 | Identification of the component of a trade item | Numeric | 4 + 18 | no |
| 8007 | International Bank Account Number | Alphanumeric | 4 + 1 to 30 | no |
| 8008 | Date and Time of Production | Numeric | 4 + 8 to 12 | no |
| 8018 | EAN.UCC Global Service Relation Number | Numeric | 4 + 18 | no |
| 8020 | Payment Slip Reference Number | Alphanumeric | 4 + 1 to 25 | no |
| 8100 | Coupon Extended Code: Number System and Offer | Numeric | 4 + 6 | no |
| 8101 | 8101 Coupon Extended Code: Number System, Offer, End of Offer | Numeric | 4 + 10 | no |
| 8102 | Coupon Extended Code: Number System preceded by 0 | Numeric | 4 + 2 | no |
| 8110 | Coupon Code Identification for Use in North America | Alphanumeric | 4 + 1 to 30 | no |
| 90 | Mutually Agreed Between Trading Partners | Alphanumeric | 2 + 1 to 30 | no |
| 91 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 92 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 93 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 94 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 95 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 96 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 97 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 98 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
| 99 | Internal Company Codes | Alphanumeric | 2 + 1 to 30 | no |
* Date is in the "YYMMDD" format.
This class inherits the BCGcode128 class.
Example
BCGgs1128's Methods
- __construct($start = NULL) — Specifies by which table the barcode should start
- getStrictMode() — Gets if the strict mode is activated
- setStrictMode($mode) — Specifies which mode to use to generate the barcode
BCGcode128's Methods
- __construct($start = NULL) — Specifies by which table the barcode should start
- setStart($start) — Specifies by which table the barcode should start
- getTilde($tilde) — Gets if the behavior for tilde ~ is modified
- setTilde($tilde) — Modifies the use of the tilde character ~
BCGBarcode1D's Methods
- getThickness() — Returns the thickness of the barcode
- setThickness($thickness) — Specifies the thickness of the barcode
- getLabel() — Gets the label
- setLabel($label) — Sets the label
- getFont() — Gets the text font for the label
- setFont($font) — Sets the text font for the label
- getChecksum() — Gets the checksum appended to the barcode
- setDisplayChecksum($display) — Specifies the checksum to be added to the label
BCGBarcode's Methods
- parse($text) — Analyzes a $text message to draw afterwards
- draw($im) — Draws the barcode on the $im
- getDimension($w, $h) — Returns an array containing the required size for the image
- getScale() — Gets the scale of the barcode
- setScale($x) — Sets the scale of the barcode
- getForegroundColor() — Gets the color of the spaces
- setForegroundColor($color) — Sets the color of the spaces
- getBackgroundColor() — Gets the color of the bars
- setBackgroundColor($color) — Sets the color of the bars
- setColor($fg, $bg) — Sets the color of the bars and spaces
- getOffsetX() — Gets the X offset
- setOffsetX($v) — Sets the X offset
- getOffsetY() — Gets the Y offset
- setOffsetY($v) — Sets the Y offset
- addLabel($label) — Adds a label to the graphic
- removeLabel($label) — Removes a label from the graphic
- clearLabels() — Removes the labels from the graphic
Code Example
<?php require('class/BCGFontFile.php'); require('class/BCGColor.php'); require('class/BCGDrawing.php'); require('class/BCGgs1128.barcode.php'); $font = new BCGFontFile('./class/font/Arial.ttf', 18); $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); // Barcode Part $code = new BCGgs1128(); $code->setScale(2); $code->setThickness(30); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->setStrictMode(true); $code->parse('011234567891234'); // Drawing Part $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?>
Methods Explanation
-
__construct($start = NULL)
— Specifies by which table the barcode should start DescriptionThe argument can be A, B, C or NULL. See the setStart() method for more information.
The default value is C. -
getStrictMode()
— Gets if the strict mode is activated DescriptionSee setStrictMode() for more details.Returnsbool - true if activated, false otherwise
-
setStrictMode($mode)
— Specifies which mode to use to generate the barcode DescriptionBy setting the argument to true, the strict mode is used, if you set false, the code will be generated following the legacy mode. For more information about those two modes, see the introduction.
The default value is true. -
__construct($start = NULL)
— Specifies by which table the barcode should start DescriptionThe argument can be A, B, C or NULL. See the setStart() method for more information.
The default value is NULL.
This means the table is automatically chosen. -
setStart($start)
— Specifies by which table the barcode should start DescriptionThe argument can be A, B, C or NULL. This selects the table the barcode will start.ReturnsThe default value is NULL.
This means the table will be automatically chosen when you provide the text.
The tables contain different characters which can be encoded in the barcode.
Check the introduction of this document to obtain more information. -
getTilde($tilde)
— Gets if the behavior for tilde ~ is modified DescriptionGets if the behavior for tilde ~ is modified.
See setTilde() for more details.Returnsbool - true if activated, false otherwise -
setTilde($tilde)
— Modifies the use of the tilde character ~ Description
- Writes a simple tilde
- ~Fx : Write a FNCx character, with x varying between 1 and 4
ReturnsThe default value is true. -
getThickness()
— Returns the thickness of the barcode DescriptionThe thickness of the barcode in pixels. The value isn't multiplied by the scale.Returnsint - value in pixels
-
setThickness($thickness)
— Specifies the thickness of the barcode DescriptionThe thickness of the barcode in pixels. This is the vertical size.
This value is multiplied by the scale. Check the setScale() method.
The default value is 30. -
getLabel()
— Gets the label DescriptionReturns the real value that will be displayed with the barcode. You have to have called the parse() method first.Returnsstring - final label
-
setLabel($label)
— Sets the label DescriptionThe text label will be written below or above the barcode depending on the barcode. You can write the special value BCGBarcode1D::AUTO_LABEL if you would like your text to be chosen automatically. It will be the value passed to the parse() method.
-
getFont()
— Gets the text font for the label DescriptionGets the text font of the label.ReturnsBCGFontFile, BCGFontPhp or int
-
setFont($font)
— Sets the text font for the label DescriptionThe value of the argument can be either an instance of the BCGFontFile class, BCGFontPhp, or a number between 1 and 5.
If you are using numbers 1 through 5, PHP fonts are used. Check the PHP Manual. -
getChecksum()
— Gets the checksum appended to the barcode DescriptionReturns the value that will be appended to the barcode. This method must be called after the method parse().Returnsint - checksum added or false if no checkum is included
-
setDisplayChecksum($display)
— Specifies the checksum to be added to the label DescriptionSetting true will append the checksum to the default label.
The default value is true. -
parse($text)
— Analyzes a $text message to draw afterwards DescriptionThe data you pass to the $text argument must be supported by the type of barcode you use.
Check each barcode's introduction section to obtain more information on how to use this method within each symbology. -
draw($im)
— Draws the barcode on the $im DescriptionThe value of the $im argument must be a GD2 image resource. The size of the image can be defined by the value received from getDimension().
-
getDimension($w, $h)
— Returns an array containing the required size for the image DescriptionReturns an array in which the first index is the image width and the second index is the image height.
The arguments are used to specify the starting point of the drawing. Should be 0 for both.
The BCGDrawing class uses this method to create the image resource.Returnsarray(int, int) - [0] is the width, [1] is the height -
getScale()
— Gets the scale of the barcode DescriptionGets the scale of the barcode. The value is the number of the "smallest" unit in pixel.Returnsint - value in pixels
-
setScale($x)
— Sets the scale of the barcode DescriptionThe barcode will be $x times bigger. Then a pixel will be $x by $x for its size.
-
getForegroundColor()
— Gets the color of the spaces DescriptionGets the color of the spaces of the barcode.Returns
- setForegroundColor($color) — Sets the color of the spaces
-
getBackgroundColor()
— Gets the color of the bars DescriptionGets the color of the bars of the barcode.Returns
- setBackgroundColor($color) — Sets the color of the bars
-
setColor($fg, $bg)
— Sets the color of the bars and spaces DescriptionAn easy and fast method to set the color of the bars and spaces. Check the setForegroundColor() and setBackgroundColor().
-
getOffsetX()
— Gets the X offset DescriptionGets the X offset of the barcode in pixels. The value isn't multiplied by the scale.Returnsint - value in pixels
-
setOffsetX($v)
— Sets the X offset DescriptionSpecifies the X offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
-
getOffsetY()
— Gets the Y offset DescriptionGets the Y offset of the barcode in pixels. The value isn't multiplied by the scale.Returnsint - value in pixels
-
setOffsetY($v)
— Sets the Y offset DescriptionSpecifies the Y offset of the barcode in pixels multiplied by the scale. The required size returned by getDimension() will be modified accordingly.
-
addLabel($label)
— Adds a label to the graphic DescriptionAdds a BCGLabel object to the drawing.
-
removeLabel($label)
— Removes a label from the graphic DescriptionRemoves a specific BCGLabel object from the drawing.
-
clearLabels()
— Removes the labels from the graphic DescriptionClears the BCGLabel objects from the drawing.
