How to generate Bar Code with PHP

Most of the time while developing e-commerce applications we need to generate Bar Code for items we are selling, we need to create a script which can generate bar codes for all items or products, most commonly it holds item number which is primary key of that item in our database, but we can also store other information too.

I have also seen Bar Codes on employee cards, cold drinks, item tags etc. I don’t know in detail about its different type but a basic demonstration is given below for how to generate Bar Code with PHP.

Here is the live demo of generate any barcode online Generate bar code

How to generate Bar Code

We need to download a php class from Github, download barcode.php file and place it your project directory.
in your file write an image tag and in src attribute type barcode.php as below.

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 blow barcode


Make sure your barcode.php path is correct, the following examples shows that barcode.php resides on the same path where we are pasting these example codes.
If you do not want to download barcode.php your can try this URL http://davidscotttufts.com/code/barcode.php just for testing purpose but for real application you must have to download barcode.php from link provided above.

Bar Code 1

Bar Code 2

Bar Code 3

To generate Bar Codes for all items in our shop database we need to loop through all items we want to generate Bar code for, And echo and image for each item then cut and stick it on the item box or tag.
We should also write another script where we can generate Bar Code for separate items one by one.

You can try other other examples changing listed parameters above. Let me know if you have any issue via comments below, help me and other developers if you have some other optimized solution.