Barcode Generator in PHP

A barcode is an optical, machine-readable, representation of data, the data usually describes something about the object that carries the barcode.Barcodes is used to store any kind of data of any object like product price, date of manufacture and other product related details. In this tutorial we will show you how to generate barcode using PHP.

Barcode Generator  in PHP

Welcome to ERPS BARCODE GENERATOR!

New barcode generator version 3.0

This project is a neat effort of creating a class that enables all kind of operations related to
BarCodes, QRCodes, DataMatrix and PDF417 using simple code and API.
No need to rely on external API... You can have your own API NOW!

Today is quite easy to find a qrcode generator, or a qrcode class, or even maybe some codebar generator or class.
But what about a class to handle all of them? What about a class that allows us to create a image, force download or save to a location with only three lines of code?

 

So here are all the features:

  • 9 QRCode types: Link, SMS, Email, Phone Number, VCard, meCard, Wifi, Geolocation and Bulk Text.
  • 10 Barcode types: UPC-A, UPC-E, EAN-8, EAN-13, CODE39, CODE93, CODE128, POSTNET, CODABAR and ISBN
  • NEW ON V3.0 Datamatrix code generator.
  • NEW ON V3.0 PDF417 code generator.
  • NEW ON V3.0 Option to show or hide the data in 1D Barcodes.
  • All barcodes are generated by code. No external API usage
  • After class initialize, one line of code does all the necessary steps and configuratios to generate code.
  • Configuration of size and colors on the same one line of code generating the code.
  • 12 methods. Generate, force download and save, for every type of code.
  • 1 PHP processor file to generate codes via POST or GET. API USAGE.
  • Support for AJAX querys via POST or GET to processor file
  • Clean and well documented code.



 

Package main files:

barcode.class.php

This is the main class file. As mentioned above it offers 6 different methods for barcode and qrcode operations. This class can be called directly and we can use the methods explained on the next topic.
 

barcode.processor.php

This is like a engine file. This PHP script can produce all operations. It's main use is for barcode and qrcode operations using POST or GET. It allows you to, for example, use a form for codes generating. It is also prepared for AJAX querys, so you can make barcode and qrcode operations with AJAX. It also helps with the code image render or forced download using HEADERS so you can display or force a download image without saving the file on filesystem.



 

Examples included:

As you can see in this example, there are all kind of examples. Although, with the suplied code you will have access to all the files. AJAX (JQuery) examples, API usage, and all barcodes and QRCodes generating examples.



 

Configuration os barcode.class.php file:

This file has only one configuration step, and it can bo most of the time optional. On line #44 there is a variable called _PROCESSOR_LOCATION_ that holds the location of itself and together with barcode_processor.php. If this two files are located on any folder of tree level down, the script will work. But if they are in the same location as the calling file then you have to set it to = "" or you can also set it to an absolute path, making it always working properlly.



 

About the methods available on barcode.class.php to use:

BarCode_link()    -> Used to retrieve a BARCODE link to show in html. No files are created, all headers
QRCode_link()     -> Used to retrieve a QRCODE link to show in html. No files are created, all headers
DataMatrix_link() -> Used to retrieve a DataMatrix link to show in html. No files are created, all headers
PDF417_link()     -> Used to retrieve a PDF417 link to show in html. No files are created, all headers

 

BarCode_dl()      -> Used to retrieve a BARCODE link with headers download. Use as link or follow it and download pops up
QRCode_dl()       -> Used to retrieve a QRCODE link with headers download. Use as link or follow it and download pops up
DataMatrix_dl()   -> Used to retrieve a DataMatrix link with headers download. Use as link or follow it and download pops up
PDF417_dl()       -> Used to retrieve a PDF417 link with headers download. Use as link or follow it and download pops up

 

BarCode_save()    -> Used to save a BARCODE on specified location. Also retrieves link to file.
QRCode_save()     -> Used to save a QRCODE on specified location. Also retrieves link to file.
DataMatrix_save() -> Used to save a DataMatrix on specified location. Also retrieves link to file.
PDF417_save()     -> Used to save a PDF417 on specified location. Also retrieves link to file.




 

Method BarCode_link() details:

This method, used to retrieve a BARCODE link for code display, has the following sintax:


 
  • BarCode_link($encoding, $bardata, $height, $scale, $bgcolor, $barcolor, $showData)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the two mandatory parameters
  4. $link1 = $bar->BarCode_link("UPC-A", "123456789012");
  5. // Extended use with all parameters
  6. $link2 = $bar->BarCode_link("CODE39", "ABC12%", 60, 2, "#ff0000", "#ffffff");
  7. // Different uses
  8. echo '';
  9. echo '';
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "";
  4. ?>

$encoding

string


This parameter will tell BarCode_link() wich barcode are we generating. Note that possible values are:
(UPC-A, UPC-E, EAN-8, EAN-13, CODE39, CODE93, CODE128, POSTNET, CODABAR or ISBN)

 

$bardata

string


This parameter will supply BarCode_link() with the data to convert to barcode. Depending on the barcode generating we have specific characters allowed and in some a maximun number of characters. See ALL BARCODES for more info on allowed charcaters and maximun number.

 

$height

(optional default = 50) integer


This parameter will tell BarCode_link() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px

 

$scale

(optional default = 2) integer


This parameter will tell BarCode_link() the desired scale. Scale is used as a multiplier for height and also a scale of barcode lenght. Due to barcode standarts, widths must be consistent so instead of desired width, wich is impossible due to variable lenght of data, we set a scale and control the final fixed height and width scale.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell BarCode_link() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell BarCode_link() the desired foreground color (bars) in hexadecimal format.

 

$showData

(optional default = 1) boolean


This parameter will tell BarCode_link() if we want to show the encoded data with the barcode. Accepted values are (1 or 0).





 

Method QRCode_link() details:

This method, used to retrieve a QRCODE link for code display, has the following sintax:


 
  • QRCode_link($qrdata_type, $data, $height, $scale, $bgcolor, $barcolor, $ECLevel, $margin)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the two mandatory parameters
  4. $qr_values[0] = 'Hello world!';
  5. $link1 = $bar->QRCode_link("text", $qr_values);
  6. // Extended use with all parameters
  7. $qr_values[0] = 'Hello world!';
  8. $link2 = $bar->QRCode_link("text", $qr_values, 60, 2);
  9. // Different uses
  10. echo '';
  11. echo '';
  12. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $qr_values[0] = 'Hello world!';
  4. echo "";
  5. ?>

$qrdata_type

string


This parameter will tell QRCode_link() wich metadata are we generating. Note that possible values are:
(text, link, sms, email, phone, vcard, mecard, wifi or geo)

 

$data

array


This parameter will supply QRCode_link() with the data to convert to qrcode. Depending on the qrcode generating we have different content and order for the array. See ALL QRCODES for more info on array values and order.

 

$height

(optional default = 50) integer


This parameter will tell QRCode_link() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px (ALSO NOTE that it will set the same width)

 

$scale

(optional default = 2) integer


This parameter will tell QRCode_link() the desired scale. Scale is used as a multiplier for height.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell QRCode_link() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell QRCode_link() the desired foreground color (bars) in hexadecimal format.

 

$ECLevel

(optional default = "L") string


This parameter will tell QRCode_link() the desired Error Correction Level. Allowed values are (L; M; Q or H)

 

$margin

(optional default = true) boolean


This parameter will tell QRCode_link() to either use a margin around the QRCode or not. Remeber that margin size will vary having in mind the data complexity, ECC Level, and QRCode size.





 

Method DataMatrix_link() details:

This method, used to retrieve a DataMatrix link for code display, has the following sintax:


 
  • DataMatrix_link($data, $height, $width, $margin, $bgcolor, $barcolor)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameter
  4. $link1 = $bar->DataMatrix_link("Hello World!");
  5. // Extended use with all parameters
  6. $link2 = $bar->DataMatrix_link("Hello World!", 200, 200, 20, "#ff6600", "#ffffff");
  7. // Use the links
  8. echo '';
  9. echo '';
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "";
  4. ?>

$data

string


This parameter will supply DataMatrix_link() with the data to convert to DataMatrix Code.

 

$height

(optional default = 100) integer


This parameter will tell DataMatrix_link() the desired height. This is an integer value. It will be considered pixels.

 

$width

(optional default = 100) integer


This parameter will tell DataMatrix_link() the desired width. This is an integer value. It will be considered pixels.

 

$margin

(optional default = 10) integer


This parameter will tell DataMatrix_link() the value in pixels for the margin.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell DataMatrix_link() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell DataMatrix_link() the desired foreground color (bars) in hexadecimal format.





 

Method PDF417_link() details:

This method, used to retrieve a PDF417 link for code display, has the following sintax:


 
  • PDF417_link($data, $height, $width, $margin, $bgcolor, $barcolor, $ECLevel)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameter
  4. $link1 = $bar->PDF417_link("Hello World!");
  5. // Extended use with all parameters
  6. $link2 = $bar->PDF417_link("Hello World!", 200, 650, 20, "#ff6600", "#ffffff", 6);
  7. // Use the links
  8. echo '';
  9. echo '';
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "";
  4. ?>

$data

string


This parameter will supply PDF417_link() with the data to convert to PDF417 Code.

 

$height

(optional default = 100) integer


This parameter will tell PDF417_link() the desired height. This is an integer value. It will be considered pixels.

 

$width

(optional default = 250) integer


This parameter will tell PDF417_link() the desired width. This is an integer value. It will be considered pixels.

 

$margin

(optional default = 10) integer


This parameter will tell PDF417_link() the value in pixels for the margin.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell PDF417_link() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell PDF417_link() the desired foreground color (bars) in hexadecimal format.

 

$ECLevel

(optional default = -1) integer


This parameter will tell PDF417_link() the desired Error Correction Level. Allowed values are (0 to 8) or (-1 for auto)





 

Method BarCode_dl() details:

This method, used to force a HTTP Header download of a BARCODE image, has the following sintax:


 
  • BarCode_dl($encoding, $bardata, $file, $type, $height, $scale, $bgcolor, $barcolor, $showData)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the three mandatory parameters
  4. $link_one = $bar->BarCode_dl("UPC-A", "12", "filename_one");
  5. // Extended use with all parameters
  6. $link_two = $bar->BarCode_dl("UPC-A", "12", "filename_two", "png", 60, 2, "#ff0000", "#0000ff");
  7. // Different uses
  8. echo $link1;
  9. echo "LINK";
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "LINK";
  4. ?>

$encoding

string


This parameter will tell BarCode_dl() wich barcode are we generating. Note that possible values are:
(UPC-A, UPC-E, EAN-8, EAN-13, CODE39, CODE93, CODE128, POSTNET, CODABAR or ISBN)

 

$bardata

string


This parameter will supply BarCode_dl() with the data to convert to barcode. Depending on the barcode generating we have specific characters allowed and in some a maximun number of characters. See ALL BARCODES for more info on allowed charcaters and maximun number.

 

$file

string


This parameter will supply BarCode_dl() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$type

(optional default = "png") string


This parameter will tell BarCode_dl() what filetype (image) it will be generated. Supported values are jpg, png or gif

 

$height

(optional default = 50) integer


This parameter will tell BarCode_dl() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px

 

$scale

(optional default = 2) integer


This parameter will tell BarCode_dl() the desired scale. Scale is used as a multiplier for height and also a scale of barcode lenght. Due to barcode standarts, widths must be consistent so instead of desired width, wich is impossible due to variable lenght of data, we set a scale and control the final fixed height and width scale.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell BarCode_dl() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell BarCode_dl() the desired foreground color (bars) in hexadecimal format.

 

$showData

(optional default = 1) boolean


This parameter will tell BarCode_link() if we want to show the encoded data with the barcode. Accepted values are (1 or 0).





 

Method QRCode_dl() details:

This method, used to force a HTTP Header download of a QRCODE image. Note that QRCodes do not allow color configurations and are provided ONLY in PNG format. The method has the following sintax:


 
  • QRCode_dl($qrdata_type, $data, $file, $height, $scale, $bgcolor, $barcolor, $ECLevel, $margin)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the three mandatory parameters
  4. $qr_values[0] = 'Hello world!';
  5. $link1      = $bar->QRCode_dl('text', $qr_values, 'filename');
  6. // Extended use with all parameters
  7. $qr_values[0] = 'Hello world!';
  8. $link2      = $bar->QRCode_dl('text', $qr_values,'filename', 50, 2);
  9. // Different uses
  10. echo $link1;
  11. echo "LINK";
  12. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $qr_values[0] = 'Hello world!';
  4. echo "LINK";
  5. ?>

$qrdata_type

string


This parameter will tell QRCode_dl() wich metadata are we generating. Note that possible values are:
(text, link, sms, email, phone, vcard, mecard, wifi or geo)

 

$data

array


This parameter will supply QRCode_dl() with the data to convert to qrcode. Depending on the qrcode generating we have different content and order for the array. See ALL QRCODES for more info on array values and order.

 

$file

string


This parameter will supply QRCode_dl() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$height

(optional default = 50) integer


This parameter will tell QRCode_dl() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px (ALSO NOTE that it will set the same width)

 

$scale

(optional default = 2) integer


This parameter will tell QRCode_dl() the desired scale. Scale is used as a multiplier for height.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell QRCode_dl() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell QRCode_dl() the desired foreground color (bars) in hexadecimal format.

 

$ECLevel

(optional default = "L") string


This parameter will tell QRCode_dl() the desired Error Correction Level. Allowed values are (L; M; Q or H)

 

$margin

(optional default = true) boolean


This parameter will tell QRCode_dl() to either use a margin around the QRCode or not. Remeber that margin size will vary having in mind the data complexity, ECC Level, and QRCode size.





 

Method DataMatrix_dl() details:

This method, used to retrieve a DataMatrix link for code display, has the following sintax:


 
  • DataMatrix_dl($data, $file, $height, $width, $margin, $bgcolor, $barcolor)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameters
  4. $link1 = $bar->DataMatrix_dl('Hello world!', 'filename');
  5. // Extended use with all parameters
  6. $link2 = $bar->DataMatrix_dl('Hello world!', 'filename', 50, 2, 15, "#ff6600", "#ffffff");
  7. // Different uses
  8. echo $link1;
  9. echo "LINK";
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "LINK";
  4. ?>

$data

string


This parameter will supply DataMatrix_dl() with the data to convert to DataMatrix Code.

 

$file

string


This parameter will supply DataMatrix_dl() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$height

(optional default = 100) integer


This parameter will tell DataMatrix_dl() the desired height. This is an integer value. It will be considered pixels.

 

$width

(optional default = 100) integer


This parameter will tell DataMatrix_dl() the desired width. This is an integer value. It will be considered pixels.

 

$margin

(optional default = 10) integer


This parameter will tell DataMatrix_dl() the value in pixels for the margin.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell DataMatrix_dl() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell DataMatrix_dl() the desired foreground color (bars) in hexadecimal format.





 

Method PDF417_dl() details:

This method, used to retrieve a DataMatrix link for code display, has the following sintax:


 
  • PDF417_dl($data, $file, $height, $width, $margin, $bgcolor, $barcolor, $ECLevel)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameters
  4. $link1 = $bar->PDF417_dl('Hello world!', 'filename');
  5. // Extended use with all parameters
  6. $link2 = $bar->PDF417_dl('Hello world!', 'filename', 50, 2, 15, "#ff6600", "#ffffff", 5);
  7. // Different uses
  8. echo $link1;
  9. echo "LINK";
  10. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. echo "LINK";
  4. ?>

$data

string


This parameter will supply PDF417_dl() with the data to convert to DataMatrix Code.

 

$file

string


This parameter will supply PDF417_dl() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$height

(optional default = 100) integer


This parameter will tell PDF417_dl() the desired height. This is an integer value. It will be considered pixels.

 

$width

(optional default = 250) integer


This parameter will tell PDF417_dl() the desired width. This is an integer value. It will be considered pixels.

 

$margin

(optional default = 10) integer


This parameter will tell PDF417_dl() the value in pixels for the margin.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell PDF417_dl() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell PDF417_dl() the desired foreground color (bars) in hexadecimal format.

 

$ECLevel

(optional default = -1) integer


This parameter will tell PDF417_dl() the desired Error Correction Level. Allowed values are (0 to 8) or (-1 for auto)





 

Method BarCode_save() details:

This method is used to save a BARCODE image on the filesystem. Note that this methods returns nothing, instead sets a $_SESSION var called $_SESSION["_CREATED_FILE_"] containing the file URL if you want to use. The path you should already know because you set it with the method. The method has the following sintax:


 
  • BarCode_save($encoding, $bardata, $file, $folder, $type, $height, $scale, $bgcolor, $barcolor, $showData)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the four mandatory parameters. File will be saved in scripts folder
  4. $bar->BarCode_save("UPC-A", "12", "filename_one", "./");
  5. // Extended use with all parameters
  6. $bar->BarCode_save("UPC-A", "12", "filename_two", "./", "png", 60, 2, "#ff0000", "#0000ff");
  7. // Uses (REMEMBER $_SESSION["_CREATED_FILE_"] will be overwritten when you call BarCode_save)
  8. echo "";
  9. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $bar->BarCode_save("UPC-A", "12", "filename_one", "./");
  4. ?>

$encoding

string


This parameter will tell BarCode_save() wich barcode are we generating. Note that possible values are:
(UPC-A, UPC-E, EAN-8, EAN-13, CODE39, CODE93, CODE128, POSTNET, CODABAR or ISBN)

 

$bardata

string


This parameter will supply BarCode_save() with the data to convert to barcode. Depending on the barcode generating we have specific characters allowed and in some a maximun number of characters. See ALL BARCODES for more info on allowed charcaters and maximun number.

 

$file

string


This parameter will supply BarCode_save() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$folder

string


This parameter will supply BarCode_save() with the desired folder to save the file. NOTE that this parameter must represent the relative path to your SCRIPT's ROOT FOLDER. You can use values like "./" to write the file to the same folder as your script, or "../" to write to one folder down of your script or "../another_folder/" to write in a another_folder wich is on folder down of your script. Also it must end with trailing slash. You can also use absolute path, but then the $_SESSION["_CREATED_FILE_"] will be useless.

 

$type

(optional default = "png") string


This parameter will tell BarCode_save() what filetype (image) it will be generated. Supported values are jpg, png or gif

 

$height

(optional default = 50) integer


This parameter will tell BarCode_save() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px

 

$scale

(optional default = 2) integer


This parameter will tell BarCode_save() the desired scale. Scale is used as a multiplier for height and also a scale of barcode lenght. Due to barcode standarts, widths must be consistent so instead of desired width, wich is impossible due to variable lenght of data, we set a scale and control the final fixed height and width scale.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell BarCode_save() the desired background color in hexadecimal format.
 

$barcolor

(optional default = "#000000") string


This parameter will tell BarCode_save() the desired foreground color (bars) in hexadecimal format.
 

$showData

(optional default = 1) boolean


This parameter will tell BarCode_link() if we want to show the encoded data with the barcode. Accepted values are (1 or 0).
 

Method QRCode_save() details:

This method is used to save a QRCODE image on the filesystem. Note that this methods returns nothing, instead sets a $_SESSION var called $_SESSION["_CREATED_FILE_"] containing the file URL if you want to use. The path you should already know because you set it with the method. The method has the following sintax:

  • QRCode_save($qrdata_type, $data, $file, $folder, $height, $scale, $bgcolor, $barcolor, $ECLevel, $margin)

Use examples:

  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the four mandatory parameters
  4. $qr_values[0] = 'Hello world!';
  5. $bar->QRCode_save('text', $qr_values, 'filename', './');
  6. // Extended use with all parameters
  7. $qr_values[0] = 'Hello world!';
  8. $bar->QRCode_save('text', $qr_values,'filename', './', 50, 2);
  9. // Uses (REMEMBER $_SESSION["_CREATED_FILE_"] will be overwritten when you call BarCode_save)
  10. echo "";
  11. ?>

Shortest form:

  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $qr_values[0] = 'Hello world!';
  4. $bar->QRCode_save('text', $qr_values, 'filename', './');
  5. ?>

$qrdata_type

string


This parameter will tell QRCode_save() wich metadata are we generating. Note that possible values are:
(text, link, sms, email, phone, vcard, mecard, wifi or geo)

 

$data

array


This parameter will supply QRCode_save() with the data to convert to qrcode. Depending on the qrcode generating we have different content and order for the array. See ALL QRCODES for more info on array values and order.
 

$file

string


This parameter will supply QRCode_save() with the filename desired so it can force a HTML Header download with the supplied filename.
 

$folder

string


This parameter will supply QRCode_save() with the desired folder to save the file. NOTE that this parameter must represent the relative path to your SCRIPT's ROOT FOLDER. You can use values like "./" to write the file to the same folder as your script, or "../" to write to one folder down of your script or "../another_folder/" to write in a another_folder wich is on folder down of your script. Also it must end with trailing slash. You can also use absolute path, but then the $_SESSION["_CREATED_FILE_"] will be useless.
 

$height

(optional default = 50) integer


This parameter will tell QRCode_save() the desired height. This is an integer value. It will be considered pixels and multiplied by scale to find the final height. So for example you set the height of 50 and the scale will be 2 so total height will be 100px (ALSO NOTE that it will set the same width)
 

$scale

(optional default = 2) integer


This parameter will tell QRCode_save() the desired scale. Scale is used as a multiplier for height.
 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell QRCode_save() the desired background color in hexadecimal format.
 

$barcolor

(optional default = "#000000") string


This parameter will tell QRCode_save() the desired foreground color (bars) in hexadecimal format.
 

$ECLevel

(optional default = "L") string


This parameter will tell QRCode_save() the desired Error Correction Level. Allowed values are (L; M; Q or H)
 

$margin

(optional default = true) boolean


This parameter will tell QRCode_save() to either use a margin around the QRCode or not. Remeber that margin size will vary having in mind the data complexity, ECC Level, and QRCode size.

Method DataMatrix_save() details:

This method is used to save a DataMatrix image on the filesystem. Note that this methods returns nothing, instead sets a $_SESSION var called $_SESSION["_CREATED_FILE_"] containing the file URL if you want to use. The path you should already know because you set it with the method. The method has the following sintax:


 
  • DataMatrix_save($bardata, $file, $folder, $height, $width, $margin, $bgcolor, $barcolor)

Use examples:

  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameters. File will be saved in scripts folder
  4. $bar->BarCode_save("Hello World!", "filename_one", "./");
  5. // Extended use with all parameters
  6. $bar->BarCode_save("Hello World!", "filename_two", "./", 150, 150, 15, "#ff0000", "#0000ff");
  7. // Uses (REMEMBER $_SESSION["_CREATED_FILE_"] will be overwritten when you call BarCode_save)
  8. echo "";
  9. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $bar->BarCode_save("Hello World!", "filename_one", "./");
  4. ?>

$bardata

string


This parameter will supply BarCode_save() with the data to convert to DataMatrix.
 

$file

string


This parameter will supply BarCode_save() with the filename desired so it can force a HTML Header download with the supplied filename.
 

$folder

string


This parameter will supply BarCode_save() with the desired folder to save the file. NOTE that this parameter must represent the relative path to your SCRIPT's ROOT FOLDER. You can use values like "./" to write the file to the same folder as your script, or "../" to write to one folder down of your script or "../another_folder/" to write in a another_folder wich is on folder down of your script. Also it must end with trailing slash. You can also use absolute path, but then the $_SESSION["_CREATED_FILE_"] will be useless.

 

$height

(optional default = 100) integer


This parameter will tell BarCode_save() the desired height. This is an integer value. It will be considered pixels.
 

$width

(optional default = 100) integer


This parameter will tell BarCode_save() the desired width. This is an integer value. It will be considered pixels.
 

$margin

(optional default = 10) integer


This parameter will tell BarCode_save() the value in pixels for the margin.
 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell BarCode_save() the desired background color in hexadecimal format.
 

$barcolor

(optional default = "#000000") string


This parameter will tell BarCode_save() the desired foreground color (bars) in hexadecimal format.

Method PDF417_save() details:

This method is used to save a PDF417 image on the filesystem. Note that this methods returns nothing, instead sets a $_SESSION var called $_SESSION["_CREATED_FILE_"] containing the file URL if you want to use. The path you should already know because you set it with the method. The method has the following sintax:


 
  • DataMatrix_save($bardata, $file, $folder, $height, $width, $margin, $bgcolor, $barcolor, $ECLevel)

Use examples:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. // Simple use with only the mandatory parameters. File will be saved in scripts folder
  4. $bar->PDF417_save("Hello World!", "filename_one", "./");
  5. // Extended use with all parameters
  6. $bar->PDF417_save("Hello World!", "filename_two", "./", 150, 300, 15, "#ff0000", "#0000ff", 5);
  7. // Uses (REMEMBER $_SESSION["_CREATED_FILE_"] will be overwritten when you call PDF417_save)
  8. echo "";
  9. ?>

Shortest form:


 
  1. require("barcode/barcode.class.php");
  2. $bar = new BARCODE();
  3. $bar->PDF417_save("Hello World!", "filename_one", "./");
  4. ?>

$bardata

string


This parameter will supply PDF417_save() with the data to convert to PDF417.

 

$file

string


This parameter will supply PDF417_save() with the filename desired so it can force a HTML Header download with the supplied filename.

 

$folder

string


This parameter will supply PDF417_save() with the desired folder to save the file. NOTE that this parameter must represent the relative path to your SCRIPT's ROOT FOLDER. You can use values like "./" to write the file to the same folder as your script, or "../" to write to one folder down of your script or "../another_folder/" to write in a another_folder wich is on folder down of your script. Also it must end with trailing slash. You can also use absolute path, but then the $_SESSION["_CREATED_FILE_"] will be useless.

 

$height

(optional default = 100) integer


This parameter will tell PDF417_save() the desired height. This is an integer value. It will be considered pixels.

 

$width

(optional default = 250) integer


This parameter will tell PDF417_save() the desired width. This is an integer value. It will be considered pixels.

 

$margin

(optional default = 10) integer


This parameter will tell PDF417_save() the value in pixels for the margin.

 

$bgcolor

(optional default = "#ffffff") string


This parameter will tell PDF417_save() the desired background color in hexadecimal format.

 

$barcolor

(optional default = "#000000") string


This parameter will tell PDF417_save() the desired foreground color (bars) in hexadecimal format.

 

$ECLevel

(optional default = -1) integer

This parameter will tell PDF417_save() the desired Error Correction Level. Allowed values are (0 to 8) or (-1 for auto)

About the processor file barcode.processor.php :

This file serves an important role of the API. It actually works as the request router. Basically it processes the requests and outputs the desired result created by the class.

It respondes to either POST or GET requests, does some initial validation and processes the request. Very usefull and it's a good choice to use instead of the API directly. Also offers compatibility with AJAX requests.

Because it uses HTML HEADER to set de desired result (output image only, force download, or save a file) normally it must be called before any HTML code.

Main feature is you can call barcode.processor.php with the appropriate values as a tag SRC, having no problems what so ever with HTML HEADERS

So for example if you call directly:

http://yourhost/barcode_folder/barcode.processor.php?encode=CODE128&bdata=AZ123456

It will automatically output to screen the barcode type CODE128 with the data AZ123456 encoded.

 

The barcode.processor.php accepts a total of 38 parameters. Of course most of them are dependent of anothers. For example if you want to generate a BARCODE of type CODABAR with the encoded value of 123, you use:

http://yourhost/barcode_folder/barcode.processor.php?encode=CODABAR&bdata=123

 

Now if you want to generate BARCODE of type UPC-A with the encoded value of 123 in a bigger size, you use:

http://yourhost/barcode_folder/barcode.processor.php?encode=UPC-A&bdata=123&height=100&scale=4

 

Now if you want to generate BARCODE of type UPC-E with the encoded value of 123 in a bigger size and different colors

http://yourhost/barcode_folder/barcode.processor.php?encode=UPC-A&bdata=123&height=100&scale=4&color=#ff6600&bgcolor=#000000

 

And if you want to generate QRCODE with data type sms you do

http://yourhost/barcode_folder/barcode.processor.php?encode=QRCODE&qrdata_type=sms&qr_sms_phone=55555&qr_sms_msg=msg here

click here and Use the QRCode Generator Tool Fully Free :  

Last but not least, is good to know that most of the requests (except the save to file functions) retrieves a link for you to use. That link is actually a processed and propper version of this examples i've shown. Passed trought more extensive validations, and preparing the link to be used. So most of the work, routing work, is done with the processor.

Step 1. Make a HTML file and define markup

We make a HTML file and save it with a name barcode.html


 

 

In this step we create a form to enter text which is going to be stored in barcode.

Step 2. Make a PHP file to generate barcode

We make a PHP file and save it with a name generate_barcode.php

";
}
?>

To generate barcode you have to download PHP - Barcode library.In this step we get the text entered by user to store in barcode and then we just send the data to barcode.php file which we downloaded to generate barcode and then display the barcode image.For more details of this library functions and query string variable visit there website.

Step 3. Make a CSS file and define styling

We make a CSS file and save it with a name barcode_style.css

body
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:100%;
 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
 background-color:#F5EEF8;
}
#wrapper
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:995px;
}
#wrapper h1
{
 margin-top:50px;
 font-size:45px;
 color:#884EA0;
}
#wrapper h1 p
{
 font-size:18px;
}
#barcode_div input[type="text"]
{
 width:300px;
 height:35px;
 border:none;
 padding-left:10px;
 font-size:17px;
}
#barcode_div input[type="submit"]
{
 background-color:#884EA0;
 border:none;
 height:35px;
 color:white;
}

That's all, this is how to generate barcode using PHP and HTML.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Any doubts, drop me a message at support@erps.in
I will answer as fast and well as I can... Promise!
Thank you.
Best regards,
erps Developer