Sunday, September 10, 2017

How to Generate Bar Code with PHP


A barcode is an optical, machine-readable, representation of data; the data usually describes something about the object that carries the barcode. Originally barcodes systematically represented data by varying the widths and spacings of parallel lines.


Barcodes were initially scanned by special optical scanners called barcode readers. Later application software became available for devices that could read images, such as smartphones with cameras.

Now a days barcodes are used by various e-commerce application that simplify the product inventory management. E-commerce sites like flipkart, amazon, snapdeal etc are using these barcode features and this barcode is available in their Invoice Bill.

How to generate Bar Code:


To generate barcodes we need to use few library files that is work with image tag of html, Which is as follow :
<img alt="my bar code" src="path/to/barcode.php" />

This script that generates barcodes in four barcode formats including Code 128, Code 39, Code 2of5, and Codabar. With a little over 100 lines of code you have the options of “vertical” or “horizontal” display, varying barcode heights, and one of four barcode formats. 

Different parameters of Bar Code:
Text: “Coding-sips”
Size: “20” (Default)
Code Type: “Code128” (Default)
                      Code 128
                      Code 39
                      Code 2of5
                      Codabar
Orientation: “Horizontal” (Default)

Print: “true” show the text below barcode

Source : https://github.com/davidscotttufts/php-barcode

Lets see the examples to generate barcode and you can use is depending upon your requirement. Make sure you must specify barcode.php file in src attribute of image tag. Otherwise it will not work.

Example : 1 (Display barcode with random product number)
<img alt="Coding Sips" src="barcode.php?text=ProductNo:-9034092348023&print=true&size=40" />



Example -2 : (Display barcode with code type :- Code39)
<img alt="Coding Sips" 
src="barcode.php?codetype=Code39&size=50&text=Coding-sips-item-no-324324&print=true"/>

Example -3 : (Display barcode with code type :- Code128)
img alt="Coding Sips" src="barcode.php?codetype=Code128&size=50&text=Coding-sips-item-no-

234234234&print=true" />
Example - 4 :(Display barcode in vertical order)
<img alt="Coding Sips" src="barcode.php?codetype=Code128&size=30&
text=Coding-sips&orientation=vertical" />


Download Demo https://github.com/skptricks/php-Tutorials/blob/master/bar%20code%20generator.rar




3 comments:

  1. Superb and handy coding, easy to use without any hassle in any way.

    ReplyDelete
  2. Thank you very much! Really easy to use.!!!

    ReplyDelete
  3. how can i change the text into parameter ? i've try but not yet success

    ReplyDelete