Manual - QRCode
Introduction
QRCode 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 number of data to be encoded and the chosen error correction level. You can force the barcode to be rendered a specific size as long as there is enough room to encode the data.
You can enter ECI mode with the function setAcceptECI().
This class inherits the BCGBarcode2D class.
Example
Methods
BCGqrcode's Methods
- getErrorLevel() — Gets the error correction level of the barcode
-
setErrorLevel(
$level ) — Sets the error correction level of the barcode - getSize() — Gets the size of the barcode
-
setSize(
$value ) — Sets the size of the barcode -
setStructuredAppend(
$snum ,$st ,$sname ) — Specifies that data will be expanded between multiple barcodes - getFNC1() — Gets if the FNC1 is activated
-
setFNC1(
$fnc1Type ,$fnc1Id ) — Transforms your barcode in GS1 or AIM standard - getAcceptECI() — Gets if ECI codes are accepted
-
setAcceptECI(
$accept ) — Specifies to accepts the ECI codes - getQuietZone() — Gets if the quiet zone will be drawn
-
setQuietZone(
$quietZone ) — Specifies to draw a quiet zone around the barcode - getMirror() — Gets if the barcode is in mirror mode
-
setMirror(
$mirror ) — Specifies to draw the barcode in mirror - getMask() — Gets the mask for the encoding
-
setMask(
$mask ) — Specifies a mask to use instead of calculating one -
setQRSize(
$qrSize ,$qrMicro ) — Specifies the size to use for the barcode
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(
$image ) — Draws the barcode on the$image -
getDimension(
$width ,$height ) — Returns an array containing the required size for the image - getScale() — Gets the scale of the barcode
-
setScale(
$scale ) — Sets the scale of the barcode - getForegroundColor() — Gets the color of the bars
-
setForegroundColor(
$color ) — Sets the color of the bars - getBackgroundColor() — Gets the color of the spaces
-
setBackgroundColor(
$color ) — Sets the color of the spaces -
setColor(
$foregroundColor ,$backgroundColor ) — Sets the color of the bars and spaces - getOffsetX() — Gets the X offset
-
setOffsetX(
$value ) — Sets the X offset - getOffsetY() — Gets the Y offset
-
setOffsetY(
$value ) — 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
use BarcodeBakery\Common\BCGColor;
use BarcodeBakery\Common\BCGDrawing;
use BarcodeBakery\Barcode\BCGqrcode;
$colorBlack = new BCGColor(0, 0, 0);
$colorWhite = new BCGColor(255, 255, 255);
// Barcode Part
$code = new BCGqrcode();
$code->setScale(3);
$code->setForegroundColor($colorBlack);
$code->setBackgroundColor($colorWhite);
$code->setErrorLevel(1);
$code->parse('QRCode');
// Drawing Part
$drawing = new BCGDrawing($code, $colorWhite);
header('Content-Type: image/png');
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>
Method explanations
-
getErrorLevel()
—
Gets the error correction level of the barcode
DescriptionThis is the error correction level percentage.Returns
int - value between 0 and 3 -
setErrorLevel(
$level ) — Sets the error correction level of the barcodeDescriptionThis is the error correction level percentage before drawing the barcode.
The level must be an integer 0 to 3, or the corresponding letter L, M, Q, H.
The error level can recover respectively, approximately 7%, 15%, 25%, and 30%.
The default value is 1 (M). -
getSize()
—
Gets the size of the barcode
DescriptionGets the size mode of the final barcode.
See setSize() for more details.Returnsint - constant value defined insetSize() -
setSize(
$value ) — Sets the size of the barcodeDescriptionThe size of the final barcode will be decided automatically depending on the data you give and the error correction level percentage you have chosen, unless you specify it with the methodsetQRSize() .
You can specify different values to this method to get a different code. There are the possible values:
BCGqrcode::QRCODE_SIZE_SMALLEST : The code will be the smallest possible
BCGqrcode::QRCODE_SIZE_MICROS : The code will be in Micro mode
BCGqrcode::QRCODE_SIZE_FULL : The code will be in Full mode
The default value isBCGqrcode::QRCODE_SIZE_FULL . -
setStructuredAppend(
$snum ,$st ,$sname ) — Specifies that data will be expanded between multiple barcodesDescriptionQRCode 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 is the identifier of your group. This argument must stay the same for every barcode in the group.
The specification indicates that this argument should be the data that will be encoded throughout all your barcodes.
Providing a big string for this argument is CPU consuming. Nothing prevents you from using a different identifier if your barcode reader supports it.
It is possible to encode the data on a maximum of 16 different barcodes.Returnsbool -true on success,false on failure -
getFNC1()
—
Gets if the FNC1 is activated
DescriptionGets if the FNC1 is activated.
See setFNC1() for more details.Returnsint - constant value defined insetFNC1() -
setFNC1(
$fnc1Type ,$fnc1Id ) — Transforms your barcode in GS1 or AIM standardDescriptionThis method will transform your barcode to accept FNC1 to be GS1 standard or AIM standard.
The first argument can be:
-BCGqrcode::QRCODE_FNC1_NONE : The code will not follow any standards.
-BCGqrcode::QRCODE_FNC1_GS1 : The code will follow the GS1 standard. The second argument is not used. Separate GS1 identifiers by %. To write a %, write it double %%.
-BCGqrcode::QRCODE_FNC1_AIM : The code will follow the AIM standard. The second argument must be used, it is the application indicator. It must be a letter (string) or 2 digits (integer).
The default value isBCGqrcode::QRCODE_FNC1_NONE . -
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 codesDescriptionBy settingtrue 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
The default value is false. -
getQuietZone()
—
Gets if the quiet zone will be drawn
Returns
bool -true if activated,false otherwise -
setQuietZone(
$quietZone ) — Specifies to draw a quiet zone around the barcodeDescriptionTo be read correctly, the QRCode must have a quiet zone around the image. You can, however, turn this off.
The default value is true. -
getMirror()
—
Gets if the barcode is in mirror mode
DescriptionGets if the barcode is in mirror mode.Returns
bool -true if activated,false otherwise -
setMirror(
$mirror ) — Specifies to draw the barcode in mirrorDescriptionIt is possible to read the barcode in mirror mode. If you set this variable totrue , the barcode will be drawn in mirror.
The default value is false. -
getMask()
—
Gets the mask for the encoding
DescriptionGets the mask for the encoding.Returns
int - value between -1 and 8 -
setMask(
$mask ) — Specifies a mask to use instead of calculating oneDescriptionQRCode calculates 8 different masks before drawing the code. A mask allows changing the appearance of the barcode in order to make it more readable for a barcode reader. Mathematical operations are executed on every mask to verify which one would fit the best. Those operations are highly CPU consuming. If the generation speed is important for you, you may want to consider forcing a specific mask. Note that your barcode may become hard to read or unreadable.
If your barcode is a Micro, the valid$mask are 0 to 3.
If your barcode is a Full, the valid$mask are 0 to 7.
If you set -1, the mask is selected automatically.
The default value is -1. -
setQRSize(
$qrSize ,$qrMicro ) — Specifies the size to use for the barcodeDescriptionBarcode Bakery 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.
The first argument is the barcode version, and the second indicates if you want a Micro mode.
If$qrMicro is set totrue , the valid$qrSize are 1 to 4.
If$qrMicro is set tofalse , the valid$qrSize are 1 to 40.
If you set -1, the barcode size will be picked automatically. The second argument doesn't matter in that case; if you want to have a Micro or a Full barcode, see the methodsetSize() .
The default value is -1.
-
setScaleX(
$scaleX ) — Sets the scaling X for the barcodeDescriptionThe 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 barcodeDescriptionThe 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 afterwardsDescriptionThe 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(
$image ) — Draws the barcode on the$image DescriptionThe value of the$image argument must be an image resource. The size of the image can be defined by the value received fromgetDimension() . -
getDimension(
$width ,$height ) — Returns an array containing the required size for the imageDescriptionReturns 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.
TheBCGDrawing 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.Returns
int - value in pixels -
setScale(
$scale ) — Sets the scale of the barcodeDescriptionThe barcode will be$x times bigger. Then a pixel will be$x by$x for its size. -
getForegroundColor()
—
Gets the color of the bars
DescriptionGets the color of the bars of the barcode.Returns
-
setForegroundColor(
$color ) — Sets the color of the bars -
getBackgroundColor()
—
Gets the color of the spaces
DescriptionGets the color of the spaces of the barcode.Returns
-
setBackgroundColor(
$color ) — Sets the color of the spaces -
setColor(
$foregroundColor ,$backgroundColor ) — Sets the color of the bars and spacesDescriptionAn easy and fast method to set the color of the bars and spaces. Check thesetForegroundColor() andsetBackgroundColor() . -
getOffsetX()
—
Gets the X offset
DescriptionGets the X offset of the barcode in pixels. The value isn't multiplied by the scale.Returns
int - value in pixels -
setOffsetX(
$value ) — Sets the X offsetDescriptionSpecifies the X offset of the barcode in pixels multiplied by the scale. The required size returned bygetDimension() 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.Returns
int - value in pixels -
setOffsetY(
$value ) — Sets the Y offsetDescriptionSpecifies the Y offset of the barcode in pixels multiplied by the scale. The required size returned bygetDimension() will be modified accordingly. -
addLabel(
$label ) — Adds a label to the graphicDescriptionAdds aBCGLabel object to the drawing. -
removeLabel(
$label ) — Removes a label from the graphicDescriptionRemoves a specificBCGLabel object from the drawing. -
clearLabels()
—
Removes the labels from the graphic
DescriptionClears the
BCGLabel objects from the drawing.