Introduction
Datamatrix code comes from the 2D barcode family. You can encode a large amount of information within a single barcode.
All the ASCII characters from 0 to 255 are supported. The barcode size will be determined by the amount of data to be encoded. The error correction level is automatically chosen.
You can enter into ECI mode with the function setAcceptECI().
This class inherits the BCGBarcode2D class.
Example
BCGdatamatrix's Methods
- getSize() — Gets the size of the barcode
- setSize($size) — Sets the size of the barcode
- getDatamatrixSize() — Gets the size to use for the barcode
- setDatamatrixSize($row, $col) — Specifies the size to use for the barcode
- getQuietZoneSize() — Gets the quiet zone size around the barcode
- setQuietZoneSize($quietZoneSize) — Specifies to draw a quiet zone around the barcode
- getTilde() — Gets if the behavior for tilde ~ is modified
- setTilde($accept) — Modifies the use of the tilde character ~
- getAcceptECI() — Gets if ECI codes are accepted
- setAcceptECI($accept) — Specifies to accepts the ECI codes
- setStructuredAppend($snum, $st, $sid) — Specifies that data will be expanded between multiple barcodes
- setFNC1($fnc1Type) — Transforms your barcode in GS1 or AIM standard
- getEncoding() — Gets the forced encoding
- setEncoding($encoding) — Sets a specific encoding
- getMacro() — Gets if a macro is written
- setMacro($macro) — Specifies to prepend and append values to your data
BCGBarcode2D's Methods
- setScaleX($scaleX) — Sets the scaling X for the barcode
- setScaleY($scaleY) — Sets the scaling Y for the barcode
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('BCGColor.php'); require('BCGDrawing.php'); require('BCGdatamatrix.barcode2d.php'); // Datamatrix Part $code = new BCGdatamatrix(); $code->setScale(3); $code->parse('Code 2D!'); // Drawing Part $color_black = new BCGColor(0, 0, 0); $color_white = new BCGColor(255, 255, 255); $drawing = new BCGDrawing('', $color_white); $drawing->setBarcode($code); $drawing->draw(); header('Content-Type: image/png'); $drawing->finish(BCGDrawing::IMG_FORMAT_PNG); ?>
Methods Explanation
-
getSize()
— Gets the size of the barcode DescriptionGets the size mode of the final barcode.
See setSize() for more details.Returnsint - constant value defined in setSize() -
setSize($size)
— Sets the size of the barcode DescriptionThe size of the final barcode will be decided automatically depending on the data you give.
You can, however, specify different values to this method to get a different code. There are the possible values:- BCGdatamatrix::DATAMATRIX_SIZE_SMALLEST : The code will be the smallest possible
- BCGdatamatrix::DATAMATRIX_SIZE_SQUARE : The code will be a square
- BCGdatamatrix::DATAMATRIX_SIZE_RECTANGLE : The code will be a rectangle
-
getDatamatrixSize()
— Gets the size to use for the barcode DescriptionGets the Datamatrix size.
See setDatamatrixSize() for more details.Returnsint[] -
setDatamatrixSize($row, $col)
— Specifies the size to use for the barcode DescriptionBarcode Generator will pick the smallest barcode size based on the information you provide.
If you wish to have a specific size, you can force the size with this method.
You must specify a valid size or this method will raise an exception.
The default value is -1. -
getQuietZoneSize()
— Gets the quiet zone size around the barcode DescriptionThe size of the quiet zone around the barcode.Returnsint - value in pixels
-
setQuietZoneSize($quietZoneSize)
— Specifies to draw a quiet zone around the barcode DescriptionTo be read correctly, Datamatrix must include a quiet zone around the image. You can, however, turn this off. The value provided is in pixels.
The default value is 1. -
getTilde()
— 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($accept)
— Modifies the use of the tilde character ~ DescriptionBy setting true in this argument, the tilde characters (ASCII 126 ~) will be processed as special characters. These are the special characters you can write.
- ~~ : Writes a simple tilde
- ~F : Writes the FNC1 character
Please note that it is possible to use ~F as the first character of your data, BUT it is possible that the automatic encoding changes the meaning of your barcode by not starting your data with a FNC1. So we recommend that you use the method setFNC1() and drop the first ~F from your data.
-
getAcceptECI()
— Gets if ECI codes are accepted DescriptionGets if ECI codes are accepted.
See setAcceptECI() for more details.Returnsbool -
setAcceptECI($accept)
— Specifies to accepts the ECI codes DescriptionBy setting true in this argument, the backslash characters (ASCII 92 \) will be processed as special characters. These are the special characters you can write.
- \\ : Writes a simple backslash
- \xxxxxx : Writes the ECI xxxxxx character with x representing an integer from 0 to 9
-
setStructuredAppend($snum, $st, $sid)
— Specifies that data will be expanded between multiple barcodes DescriptionDatamatrix code data can be separated throughout many different barcodes.
The first argument is the barcode number (beginning with 1), the second argument is the total number of barcodes you have. The last argument specifies an identifier for your barcode group. This argument must be a number between 1 and 64516 and it must stay the same for each barcode in the group.
It is possible to encode the data on a maximum of 16 different barcodes.Returnsbool - true on success, false on failure -
setFNC1($fnc1Type)
— Transforms your barcode in GS1 or AIM standard DescriptionThis method will transform your barcode to accept FNC1 to be GS1 standard or AIM standard.
- BCGdatamatrix::DATAMATRIX_FNC1_NONE : The code will not follow any standards.
- BCGdatamatrix::DATAMATRIX_FNC1_GS1 : The code will follow the GS1 standard.
Separate GS1 identifiers by ~F. Don't forget to turn on setTilde(). - BCGdatamatrix::DATAMATRIX_FNC1_AIM : The code will follow the AIM standard.
Please note that it is possible to use ~F as the first character of your data, BUT it is possible that the automatic encoding changes the meaning of your barcode by not starting your data with a FNC1. So we recommend that you use the method setFNC1() and drop the first ~F from your data.
-
getEncoding()
— Gets the forced encoding DescriptionGets the forced encoding.
See setEncoding() for more details.Returnsint - constant value defined in setEncoding() -
setEncoding($encoding)
— Sets a specific encoding DescriptionYou can force an encoding to be used for different reasons. Some readers are not able to read a specific encoding, so you can force the ASCII mode.
Note that by forcing the encoding, you may not get an efficient result. Furthermore, some characters cannot be represented in some encodings.
See the technical information page for more information about the encodings.- BCGdatamatrix::DATAMATRIX_ENCODING_UNKNOWN : No specific encoding is selected
- BCGdatamatrix::DATAMATRIX_ENCODING_ASCII : ASCII and extended ASCII (low compression)
- BCGdatamatrix::DATAMATRIX_ENCODING_C40 : C40 encoding (capital letters)
- BCGdatamatrix::DATAMATRIX_ENCODING_TEXT : TEXT encoding (lowercase letters)
- BCGdatamatrix::DATAMATRIX_ENCODING_X12 : X12 encoding (capital letters and numbers)
- BCGdatamatrix::DATAMATRIX_ENCODING_EDIFACT : Edifact encoding
- BCGdatamatrix::DATAMATRIX_ENCODING_BASE256 : Binary encoding
-
getMacro()
— Gets if a macro is written DescriptionGets if a macro is written.
See setMacro() for more details.Returnsint - constant value defined in setMacro() -
setMacro($macro)
— Specifies to prepend and append values to your data DescriptionThe macro has been defined to make your data and barcode smaller in size. Use this method to prepend and append predefined data in your barcode when read.
- BCGdatamatrix::DATAMATRIX_MACRO_NONE : Your data will appear raw. No prefix or suffix.
- BCGdatamatrix::DATAMATRIX_MACRO_05 : Prefix: [)>RS05GS - Suffix: RSEoT
- BCGdatamatrix::DATAMATRIX_MACRO_06 : Prefix: [)>RS06GS - Suffix: RSEoT
-
setScaleX($scaleX)
— Sets the scaling X for the barcode DescriptionThe width in pixel of one module.
The default value is 1.
Note that this method is protected. -
setScaleY($scaleY)
— Sets the scaling Y for the barcode DescriptionThe height in pixel of one module.
The default value is 1.
Note that this method is protected. -
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.
