<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code-diesel &#187; barcodes</title>
	<atom:link href="http://www.codediesel.com/tag/barcodes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using barcodes in your web application</title>
		<link>http://www.codediesel.com/php/using-barcodes-in-your-web-application/</link>
		<comments>http://www.codediesel.com/php/using-barcodes-in-your-web-application/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 04:56:56 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[barcodes]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=1518</guid>
		<description><![CDATA[application of bar codes in your web programs]]></description>
			<content:encoded><![CDATA[<p>Brought into the mainstream by supermarket checkout systems, bar codes have become a ubiquitous element in our daily lives. Rarely will one come across any product that doesn&#8217;t have a barcode. The idea of a barcode originated in 1932 from the thesis of Wallace Flint at Harvard.<br />
<span id="more-1518"></span></p>
<h4>Varieties of barcodes</h4>
<p>Barcodes bascially come in two main type: linear (1-dimensional) and Matrix (2-dimensional) with each offering a variety of formats, depending on your application purpose. The barcodes we usually see on books and other standard products are of the linear type. These only encode data in one dimension, from left to right. The following shows a typical UPC barcode.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/bar2.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/bar2.png" alt="bar2" title="bar2" width="109" height="70" class="aligncenter size-full wp-image-1543" /></a></p>
<p>Matrix or 2-dimensional barcode encode information in both directions (x-y axis). So they are able to store more information in the same space then linear barcodes. There are many type of matrix codes, the one shown below is that of <a target="_blank" href="http://en.wikipedia.org/wiki/QR_Code">QR-Code</a> or Quick Response code. QR-Codes are mostly used for access with cell phones and have become a de-facto standard for Japanese cell phones. Other type of matrix codes include <a target="_blank" href="http://en.wikipedia.org/wiki/ShotCode">ShotCode</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/Semacode">Semacode</a>. The QR-code below shows the string &#8216;codediesel.com&#8217; encoded.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/qr_code.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/qr_code.png" alt="qr_code" title="qr_code" width="116" height="116" class="aligncenter size-full wp-image-1547" /></a></p>
<p>In this post we will see how to generate linear barcodes using a pear library.</p>
<h4>Installation</h4>
<p>We will be using the &#8216;Image_Barcode&#8217; Pear library to generate linear barcodes. You can download the library manually from <a target="_blank" href="http://pear.php.net/package/Image_Barcode/download">here</a>, or use the pear installer.</p>

<div class="wp_codebox"><table><tr id="p15181"><td class="code" id="p1518code1"><pre class="txt" style="font-family:monospace;">pear install Image_Barcode-1.1.0</pre></td></tr></table></div>

<h4>Sample Code</h4>
<p>A sample code for generating a CODE128 barcode is shown below.</p>

<div class="wp_codebox"><table><tr id="p15182"><td class="code" id="p1518code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">require_once</span> <span style="color: #0000ff;">'Barcode.php'</span><span style="color: #339933;">;</span>
   <span style="color: #009933; font-style: italic;">/* Data that will be encoded in the bar code */</span>
   <span style="color: #000088;">$bar_code_data</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;TRSD5656&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #009933; font-style: italic;">/* The third parameter can accept any from the following,
    * jpg, png and gif.
    */</span>
   Image_Barcode<span style="color: #339933;">::</span><span style="color: #004000;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bar_code_data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'code128'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>By default, the image generated by the barcode is directly output to the browser. If you do not want this, you can pass &#8216;false&#8217; as the fourth parameter and it will return the GD image resource object; allowing you to do further things with it.</p>

<div class="wp_codebox"><table><tr id="p15183"><td class="code" id="p1518code3"><pre class="php" style="font-family:monospace;">Image_Barcode<span style="color: #339933;">::</span><span style="color: #004000;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bar_code_data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'code128'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'png'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Supported Types</h4>
<p>The &#8216;Image_Barcode&#8217; library supports the following barcode types:</p>
<ul>
<li>Code 39</li>
<li>Code 128</li>
<li>EAN 13</li>
<li>INT 25</li>
<li>PostNet</li>
<li>UPCA</li>
</ul>
<h4>Some sample generated barcodes</h4>
<p>Some barcodes generated with the above library are shown below. The last one is the United States Postal Service format.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/barcode_example.gif"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/barcode_example.gif" alt="barcode_example" title="barcode_example" width="557" height="103" class="aligncenter size-full wp-image-1534" /></a><br />
<br clear="left" /></p>
<h4>Google charts and QR-Codes</h4>
<p>Before closing this post we will take a look at generating QR-Codes using Google charts. The following line for example generates the QR-Code shown below. The &#8216;chl&#8217; parameter specifies the data that will be encoded (&#8216;www.codediesel.com&#8217; here).</p>

<div class="wp_codebox"><table><tr id="p15184"><td class="code" id="p1518code4"><pre class="html" style="font-family:monospace;">http://chart.apis.google.com/chart
?cht=qr&amp;chs=150x150&amp;chl=www.codediesel.com</pre></td></tr></table></div>

<p>Which you can embed in your html as below:</p>

<div class="wp_codebox"><table><tr id="p15185"><td class="code" id="p1518code5"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://chart.apis.google.com/chart
?cht=qr&amp;chs=150x150&amp;chl=www.codediesel.com&quot; /&gt;</pre></td></tr></table></div>

<p><a href="http://www.codediesel.com/wp-content/uploads/2009/09/google_chart_qrcode.png"><img src="http://www.codediesel.com/wp-content/uploads/2009/09/google_chart_qrcode.png" alt="google_chart_qrcode" title="google_chart_qrcode" width="150" height="150" class="aligncenter size-full wp-image-1554" /></a></p>
<h4>Testing bar codes</h4>
<p>Ok, now you have created all the barcodes you want, but the problem is you do not have a barcode reader handy; no sweat, <a target="_blank" href="http://www.qualitysoft.de/index_en.html">Qualitysoft.de</a> offers a free barcode testing application for checking a plethora of barcode formats.<br />
<br/><br/></p>
<h4>Additional Resources</h4>
<p>1. <a target="_blank" href="http://qrcode.kaywa.com/">http://qrcode.kaywa.com/</a><br />
2. <a target="_blank" href="http://www.denso-wave.com/qrcode/index-e.html">http://www.denso-wave.com/qrcode/index-e.html</a><br />
3. <a target="_blank" href="http://en.wikipedia.org/wiki/Barcode">http://en.wikipedia.org/wiki/Barcode</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/using-barcodes-in-your-web-application/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

