Introduction
ISBN code is used to keep a track of the books in the marketplace. It is based on EAN-13 code. An ISBN code can contain 10 characters, in this case, 978 or 979 will be prefixed to encode in the EAN-13 mode.
The hyphens are optional and are different depending on the distribution agency. You may include them, but they will be ignored when read. Barcode Generator inserts some hyphens in order to look similar to ISBN text.
This class inherits the BCGean13 class.
Example
BCGisbn's Methods
- __construct($gs1 = self::GS1_AUTO, $isbn_text = BarCode1D::AUTO_LABEL, $isbn_font = null) — Specifies many parameters before creating the barcode
- setGS1($gs1) — Specifies which characters will be prefixed.
- setISBNText($text) — Specifies the label over the barcode
- setISBNFont($font) — Specifies the font of the label over the barcode
BCGean13's Methods
- No specific methods for this class.
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/BCGisbn.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 BCGisbn(); $code->setScale(2); $code->setThickness(30); $code->setForegroundColor($color_black); $code->setBackgroundColor($color_white); $code->setFont($font); $code->parse('9780672326970'); // 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($gs1 = self::GS1_AUTO, $isbn_text = BarCode1D::AUTO_LABEL, $isbn_font = null)
— Specifies many parameters before creating the barcode DescriptionTo understand the meaning of every argument, check all the corresponding methods.
All the arguments have a default value, it is written in italic.- $gs1: setGS1() (BCGisbn::GS1_AUTO)
- $isbn_text: setISBNText() (BCGBarcode1D::AUTO_LABEL)
- $isbn_font: setISBNFont() (null)
-
setGS1($gs1)
— Specifies which characters will be prefixed. DescriptionThe different values for this argument are:
- BCGisbn::GS1_AUTO : Does the same thing as BCGisbn::GS1_PREFIX978
- BCGisbn::GS1_PREFIX978 : Adds 978 in front of the code
- BCGisbn::GS1_PREFIX979 : Adds 979 in front of the code
-
setISBNText($text)
— Specifies the label over the barcode DescriptionThe default value is BCGBarcode1D::AUTO_LABEL.
By setting this value, the text "ISBN ..." will be automatically written when the barcode is drawn. -
setISBNFont($font)
— Specifies the font of the label over the barcode DescriptionThe value of the argument can be either an instance of the BCGFont class or a number between 1 and 5.
You can specify a specific font with BCGFont, or when a number is inserted, PHP fonts are used. Check the PHP Manual. -
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.
