473,791 Members | 2,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Barcode generation

40 New Member
I am doing an inventory control project and i want to create barcodes for the products in addition to the product details in a form.The form values should be submitted to the database to retrieve for future use.How to generate a barcode,how to load it in the database and retrieve it back.can i generate the barcode and submit the form with a single "submit" button?pls guide me in this issue.The following code is used to generate a barcode.i just dont know how to implement it in my form.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Startup code
  4. //-----------------------------------------------------------------------------
  5.  
  6.  
  7. if(isset($_GET["text"])) $text=$_GET["text"];
  8. if(isset($_GET["format"])) $format=$_GET["format"];
  9. if(isset($_GET["quality"])) $quality=$_GET["quality"];
  10. if(isset($_GET["width"])) $width=$_GET["width"];
  11. if(isset($_GET["height"])) $height=$_GET["height"];
  12. if(isset($_GET["type"])) $type=$_GET["type"];
  13. if(isset($_GET["barcode"])) $barcode=$_GET["barcode"];
  14.  
  15.  
  16.  
  17.  
  18. if (!isset ($text)) $text = 1;
  19. if (!isset ($type)) $type = 1;
  20. if (empty ($quality)) $quality = 100;
  21. if (empty ($width)) $width = 160;
  22. if (empty ($height)) $height = 80;
  23. if (!empty ($format)) $format = strtoupper ($format);
  24.         else $format="PNG";
  25.  
  26.  
  27. switch ($type)
  28. {
  29.         default:
  30.                 $type = 1;
  31.         case 1:
  32.                 Barcode39 ($barcode, $width, $height, $quality, $format, $text);
  33.                 break;          
  34. }
  35.  
  36.  
  37. //-----------------------------------------------------------------------------
  38. // Generate a Code 3 of 9 barcode
  39. //-----------------------------------------------------------------------------
  40. function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
  41. {
  42.         switch ($format)
  43.         {
  44.                 default:
  45.                         $format = "JPEG";
  46.                 case "JPEG": 
  47.                         header ("Content-type: image/jpeg");
  48.                         break;
  49.                 case "PNG":
  50.                         header ("Content-type: image/png");
  51.                         break;
  52.                 case "GIF":
  53.                         header ("Content-type: image/gif");
  54.                         break;
  55.         }
  56.  
  57.  
  58.         $im = ImageCreate ($width, $height)
  59.     or die ("Cannot Initialize new GD image stream");
  60.         $White = ImageColorAllocate ($im, 255, 255, 255);
  61.         $Black = ImageColorAllocate ($im, 0, 0, 0);
  62.         //ImageColorTransparent ($im, $White);
  63.         ImageInterLace ($im, 1);
  64.  
  65.  
  66.  
  67.         $NarrowRatio = 20;
  68.         $WideRatio = 55;
  69.         $QuietRatio = 35;
  70.  
  71.  
  72.         $nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
  73.         $Pixels = $width / $nChars;
  74.         $NarrowBar = (int)(20 * $Pixels);
  75.         $WideBar = (int)(55 * $Pixels);
  76.         $QuietBar = (int)(35 * $Pixels);
  77.  
  78.  
  79.         $ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);
  80.  
  81.         if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
  82.         {
  83.                 ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
  84.                 OutputImage ($im, $format, $quality);
  85.                 exit;
  86.         }
  87.  
  88.         $CurrentBarX = (int)(($width - $ActualWidth) / 2);
  89.         $Color = $White;
  90.         $BarcodeFull = "*".strtoupper ($barcode)."*";
  91.         settype ($BarcodeFull, "string");
  92.  
  93.         $FontNum = 3;
  94.         $FontHeight = ImageFontHeight ($FontNum);
  95.         $FontWidth = ImageFontWidth ($FontNum);
  96.         if ($text != 0)
  97.         {
  98.                 $CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
  99.                 ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
  100.         }
  101.         else
  102.         {
  103.             $FontHeight=-2;
  104.         }
  105.  
  106.  
  107.         for ($i=0; $i<strlen($BarcodeFull); $i++)
  108.         {
  109.                 $StripeCode = Code39 ($BarcodeFull[$i]);
  110.  
  111.  
  112.                 for ($n=0; $n < 9; $n++)
  113.                 {
  114.                         if ($Color == $White) $Color = $Black;
  115.                         else $Color = $White;
  116.  
  117.  
  118.                         switch ($StripeCode[$n])
  119.                         {
  120.                                 case '0':
  121.                                         ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
  122.                                         $CurrentBarX += $NarrowBar;
  123.                                         break;
  124.  
  125.  
  126.                                 case '1':
  127.                                         ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
  128.                                         $CurrentBarX += $WideBar;
  129.                                         break;
  130.                         }
  131.                 }
  132.  
  133.  
  134.                 $Color = $White;
  135.                 ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
  136.                 $CurrentBarX += $QuietBar;
  137.         }
  138.  
  139.  
  140.         OutputImage ($im, $format, $quality);
  141. }
  142.  
  143.  
  144. //-----------------------------------------------------------------------------
  145. // Output an image to the browser
  146. //-----------------------------------------------------------------------------
  147. function OutputImage ($im, $format, $quality)
  148. {
  149.         switch ($format)
  150.         {
  151.                 case "JPEG": 
  152.                         ImageJPEG ($im, "", $quality);
  153.                         break;
  154.                 case "PNG":
  155.                         ImagePNG ($im);
  156.                         break;
  157.                 case "GIF":
  158.                         ImageGIF ($im);
  159.                         break;
  160.         }
  161. }
  162.  
  163.  
  164. //-----------------------------------------------------------------------------
  165. // Returns the Code 3 of 9 value for a given ASCII character
  166. //-----------------------------------------------------------------------------
  167. function Code39 ($Asc)
  168. {
  169.         switch ($Asc)
  170.         {
  171.                 case ' ':
  172.                         return "011000100";     
  173.                 case '$':
  174.                         return "010101000";             
  175.                 case '%':
  176.                         return "000101010"; 
  177.                 case '*':
  178.                         return "010010100"; // * Start/Stop
  179.                 case '+':
  180.                         return "010001010"; 
  181.                 case '|':
  182.                         return "010000101"; 
  183.                 case '.':
  184.                         return "110000100"; 
  185.                 case '/':
  186.                         return "010100010"; 
  187.                 case '-':
  188.                         return "010000101";
  189.                 case '0':
  190.                         return "000110100"; 
  191.                 case '1':
  192.                         return "100100001"; 
  193.                 case '2':
  194.                         return "001100001"; 
  195.                 case '3':
  196.                         return "101100000"; 
  197.                 case '4':
  198.                         return "000110001"; 
  199.                 case '5':
  200.                         return "100110000"; 
  201.                 case '6':
  202.                         return "001110000"; 
  203.                 case '7':
  204.                         return "000100101"; 
  205.                 case '8':
  206.                         return "100100100"; 
  207.                 case '9':
  208.                         return "001100100"; 
  209.                 case 'A':
  210.                         return "100001001"; 
  211.                 case 'B':
  212.                         return "001001001"; 
  213.                 case 'C':
  214.                         return "101001000";
  215.                 case 'D':
  216.                         return "000011001";
  217.                 case 'E':
  218.                         return "100011000";
  219.                 case 'F':
  220.                         return "001011000";
  221.                 case 'G':
  222.                         return "000001101";
  223.                 case 'H':
  224.                         return "100001100";
  225.                 case 'I':
  226.                         return "001001100";
  227.                 case 'J':
  228.                         return "000011100";
  229.                 case 'K':
  230.                         return "100000011";
  231.                 case 'L':
  232.                         return "001000011";
  233.                 case 'M':
  234.                         return "101000010";
  235.                 case 'N':
  236.                         return "000010011";
  237.                 case 'O':
  238.                         return "100010010";
  239.                 case 'P':
  240.                         return "001010010";
  241.                 case 'Q':
  242.                         return "000000111";
  243.                 case 'R':
  244.                         return "100000110";
  245.                 case 'S':
  246.                         return "001000110";
  247.                 case 'T':
  248.                         return "000010110";
  249.                 case 'U':
  250.                         return "110000001";
  251.                 case 'V':
  252.                         return "011000001";
  253.                 case 'W':
  254.                         return "111000000";
  255.                 case 'X':
  256.                         return "010010001";
  257.                 case 'Y':
  258.                         return "110010000";
  259.                 case 'Z':
  260.                         return "011010000";
  261.                 default:
  262.                         return "011000100"; 
  263.         }
  264. }
  265.  
  266.  
  267. ?>
Oct 21 '08 #1
7 4836
Dormilich
8,658 Recognized Expert Moderator Expert
How to generate a barcode,how to load it in the database and retrieve it back.can i generate the barcode and submit the form with a single "submit" button?pls guide me in this issue.The following code is used to generate a barcode.i just dont know how to implement it in my form.
- As I see it the script will do that
- the barcode is a picture (thus binary content)
- dito (but I think it's a good idea to store the actual value too)
- first submit, then generate (and do all the stuff you want with the barcode)
- what is the form expected to do?

regards
Oct 21 '08 #2
divyac
40 New Member
- As I see it the script will do that
- the barcode is a picture (thus binary content)
- dito (but I think it's a good idea to store the actual value too)
- first submit, then generate (and do all the stuff you want with the barcode)
- what is the form expected to do?

regards
The form is used to load the required details like cost price,selling price,discounts allowed,etc..fo r the new product which should be retrieved back from the database once when the id of that product is given including the barcode.what value should i give to generate a barcode?
Oct 21 '08 #3
dlite922
1,584 Recognized Expert Top Contributor
The form is used to load the required details like cost price,selling price,discounts allowed,etc..fo r the new product which should be retrieved back from the database once when the id of that product is given including the barcode.what value should i give to generate a barcode?
That's easy: a value that uniquely identifies that item, such as a product number or product ID.


This is a great idea. It really stretches the limit on what you could do with a PHP application. After so many years, people still don't fully understand the possibilities and capabilites of PHP.




Dan
Oct 21 '08 #4
code green
1,726 Recognized Expert Top Contributor
I might be missing something but what use is a barcode on a web page?
And why store it as a JPEG etc?

Barcodes are read by barcode scanners.
Is somebody going to to be waving a scanner in front of a monitor?

I am asking because I don't want divyac producing something impractical (unless this is just for fun).

I have written php scripts that generate barcodes onto packing lists, stock control proformas etc.

And as barcodes are usually!?! on paper the output was done on PDF (FPDF class).
In this case a barcode is simply a font, so you don't need a picture of anything,
simply a font file
Oct 21 '08 #5
divyac
40 New Member
I might be missing something but what use is a barcode on a web page?
And why store it as a JPEG etc?

Barcodes are read by barcode scanners.
Is somebody going to to be waving a scanner in front of a monitor?

I am asking because I don't want divyac producing something impractical (unless this is just for fun).

I have written php scripts that generate barcodes onto packing lists, stock control proformas etc.

And as barcodes are usually!?! on paper the output was done on PDF (FPDF class).
In this case a barcode is simply a font, so you don't need a picture of anything,
simply a font file


My client asked this work in a very simple way and in a very short period.so i haven't tried out PDF generation.I think he would take the print of the barcode from the web page itself.

Also,once I generated a PDF document but when i tried to open that document it showed some error and i couldn't open it.Can you just guide me through in this issue??

Thanks
Divya
Oct 22 '08 #6
code green
1,726 Recognized Expert Top Contributor
I have only written PDF docs using an open source class FPDF FPDF I also know of ezPDF.
Creating PDF is slow and fiddly, but so is any programming requiring a printout.
People think it is simple only because they have been spoilt with microsoft office
Printing from a web page has hidden problems (size, browser variations etc)
whereas PDF is precise.

Take a look at the FPDF site and see what you think
Oct 22 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
5310
by: Tom Turner | last post by:
Here's the background on my situation. The question follows --- We have 600 units of mail going from our business to various Post Offices every morning. Every unit is accompanied by a paper Verification form which is signed and dated by a postal employee and returned to our office as proof of delivery. The Verification contains a 24 character barcode which holds a non-unique 5 digit postal zip code at pos 5-9, and a unique 10- digit...
4
2124
by: | last post by:
Hi all, we have a need to barcode encode and display a record identifier (number) both in html in the browser and through fdf in adobe acrobat in realtime. Is this possible? Can anyone make any recommendations on software to do this? thanks!
6
3384
by: Samuel Shulman | last post by:
I would like to add barcode functionality to my POS program How does one attach barcode reader is it usually USB port How can the program get the data read by the device Thank you, Samuel
0
1025
by: Dilip | last post by:
hi ppl , i need some help in generating barcode text thro FOP .. i am succesfull in creating a input number as a barcode value.. but the problem is i need the barcode to be displayed vertically i have used code-39-30 font . created an xml document for the font that is a font file metrics.. is there any way to display the text vertically
10
1586
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi everyone! Does anyone know what do I need (control or anything else) in order to provide it with a number (fixed digits) and let it created a barcode for me, which I could scan later using a scanner and produce that number back? Thanks in advance!
7
8290
by: Alper Ozgur | last post by:
Hi; How can i capture and decode the barcode that reading by an usb Barcode reader?
4
3142
by: wassimdaccache | last post by:
Hello everybody Does someone have a VB module and FONT for windows XP SP2 to import into a MSaccess (2003) to print a barecode ... Please leave me any comments about barecode generation or anything u know about barecode...
7
4224
by: jim | last post by:
I need to have 2 simple barcode reader applications finished by midnight tonight. I have never written any barcode reader software and need any help that you may be able to offer. I do not know what type of barcode the user will have, so I need to be able to accept input from any industry standard barcode reader. I need to check the barcodes scanned to see if they are in a database of acceptable barcodes and simply show ACCEPT or...
6
9813
by: Robocop | last post by:
Does anyone know of any decent (open source or commercial) python barcode recognition tools or libraries. I need to read barcodes from pdfs or images, so it will involve some OCR algorithm. I also only need to read the code 93 symbology, so it doesn't have to be very fancy. The most important thing to me is that it outputs in some python friendly way, or ideally that it is written in python. Any tips would be great!
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.