532 lines
51 KiB
HTML
532 lines
51 KiB
HTML
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Example scripts</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets V1.76.0"><link rel="home" href="index.html" title="JpGraph Manual"><link rel="up" href="ch27.html" title="Chapter 27. QR (2D-Barcode)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Example scripts</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center">Chapter 27. QR (2D-Barcode)</th><td width="20%" align="right"> </td></tr></table><hr></div><div class="sect1" title="Example scripts"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2618696"></a>Example scripts</h2></div></div></div>
|
||
|
||
<p>The following sections shows a number of example script that can be used as a base for
|
||
further refinement.</p>
|
||
<div class="sect2" title="Example 1 - Store QR code to file"><div class="titlepage"><div><div><h3 class="title"><a name="id2618715"></a>Example 1 - Store QR code to file</h3></div></div></div>
|
||
|
||
<p>QR Barcode with specified version and stored to a file</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample03"></a><p class="title"><b>Example 27.6. Storing image to a file (<code class="filename">qrexample03.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 3 : QR Barcode with specified version and stored to a file</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">01234567</span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Use QR version 3</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$fileName</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">qrexample03.png</span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder and let the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> decide a suitable error level</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size (quite big)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-code">,</span><span class="hl-var">$fileName</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-reserved">list</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$errorcorrection</span><span class="hl-brackets">)</span><span class="hl-code"> = </span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">GetQRInfo</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">"</span><span class="hl-string">QR Barcode, (<b>Version: </span><span class="hl-var">$version</span><span class="hl-string">-</span><span class="hl-var">$errorcorrection</span><span class="hl-string"></b>), image stored in file </span><span class="hl-var">$fileName</span><span class="hl-quotes">"</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 2 - Specified error correction level"><div class="titlepage"><div><div><h3 class="title"><a name="id2618745"></a>Example 2 - Specified error correction level</h3></div></div></div>
|
||
|
||
<p>QR Barcode with specified version and error correction level</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample04"></a><p class="title"><b>Example 27.7. Specified error correction level (<code class="filename">qrexample04.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 4 : QR Barcode with specified version and error correction level</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">01234567</span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = </span><span class="hl-number">12</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Use QR version 4</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$corrlevel</span><span class="hl-code"> = </span><span class="hl-identifier">QRCapacity</span><span class="hl-code">::</span><span class="hl-identifier">ErrH</span><span class="hl-code"> ; </span><span class="hl-comment">//</span><span class="hl-comment"> Level H error correction (the highest possible)</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder using the specified</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> QR version and error correction</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$corrlevel</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample04"></a><p class="title"><b>Figure 27.14. Specified error correction level <code class="uri"><a class="uri" href="example_src/qrexample04.html" target="_top">(<code class="filename">qrexample04.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample04.png" alt="Specified error correction level (qrexample04.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 3 - Manual specified encoding"><div class="titlepage"><div><div><h3 class="title"><a name="id2618804"></a>Example 3 - Manual specified encoding</h3></div></div></div>
|
||
|
||
<p>QR Barcode with manually specified encodation</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample05"></a><p class="title"><b>Example 27.8. QR Barcode with manually specified encodation (<code class="filename">qrexample05.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
28
|
||
29
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 5 : QR Barcode with manually specified encodation</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> We want the data to be encoded using alphanumeric encoding even though</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> it is only numbers</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
|
||
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-identifier">QREncoder</span><span class="hl-code">::</span><span class="hl-identifier">MODE_ALPHANUM</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">01234567</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">
|
||
</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Use QR version 3</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$corrlevel</span><span class="hl-code"> = </span><span class="hl-identifier">QRCapacity</span><span class="hl-code">::</span><span class="hl-identifier">ErrH</span><span class="hl-code"> ; </span><span class="hl-comment">//</span><span class="hl-comment"> Level H error correction (the highest possible)</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder using the specified</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> QR version and error correction</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$corrlevel</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">4</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample05"></a><p class="title"><b>Figure 27.15. QR Barcode with manually specified encodation <code class="uri"><a class="uri" href="example_src/qrexample05.html" target="_top">(<code class="filename">qrexample05.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample05.png" alt="QR Barcode with manually specified encodation (qrexample05.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 4 - JPEG image format"><div class="titlepage"><div><div><h3 class="title"><a name="id2618868"></a>Example 4 - JPEG image format</h3></div></div></div>
|
||
|
||
<p>QR Barcode with image in JPG format</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample06"></a><p class="title"><b>Example 27.9. QR Barcode with image in JPG format (<code class="filename">qrexample06.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 6 : QR Barcode with image in JPG format</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">ABCDEFGH01234567</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = -</span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1 = Let the library decide version (same as default)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$corrlevel</span><span class="hl-code"> = -</span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1 = Let the library decide error correction level (same as default)</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder using the specified</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> QR version and error correction</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$corrlevel</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">=</span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use JPEG format with 80% quality level</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetImgFormat</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpeg</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-number">80</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">4</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample06"></a><p class="title"><b>Figure 27.16. QR Barcode with image in JPG format <code class="uri"><a class="uri" href="example_src/qrexample06.html" target="_top">(<code class="filename">qrexample06.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample06.png" alt="QR Barcode with image in JPG format (qrexample06.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 5 - Multiple manual encoding"><div class="titlepage"><div><div><h3 class="title"><a name="id2618932"></a>Example 5 - Multiple manual encoding</h3></div></div></div>
|
||
|
||
<p>QR Barcode with multiple manually specified encodation schema. </p>
|
||
<p>
|
||
</p><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
|
||
<p>Normally there would be no need to ever use manually specified
|
||
encodation)</p>
|
||
</div><p>
|
||
</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample07"></a><p class="title"><b>Example 27.10. multiple manually specified encodation schema. (<code class="filename">qrexample07.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 7 : QR Barcode with multiple manually specified encodation schemas</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> (</span><span class="hl-inlinedoc">Note:</span><span class="hl-comment"> Normally there would be no need to ever use manually specified encodation)</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-code">
|
||
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-identifier">QREncoder</span><span class="hl-code">::</span><span class="hl-identifier">MODE_ALPHANUM</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">01234567</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">,
|
||
</span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-identifier">QREncoder</span><span class="hl-code">::</span><span class="hl-identifier">MODE_NUMERIC</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">89012345</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">
|
||
</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder (automatically determined QR version and</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> error correction level)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">4</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample07"></a><p class="title"><b>Figure 27.17. multiple manually specified encodation schema. <code class="uri"><a class="uri" href="example_src/qrexample07.html" target="_top">(<code class="filename">qrexample07.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample07.png" alt="multiple manually specified encodation schema. (qrexample07.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 6 - Reading data from file"><div class="titlepage"><div><div><h3 class="title"><a name="id2619008"></a>Example 6 - Reading data from file</h3></div></div></div>
|
||
|
||
<p>QR Barcode with data read from file</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample08"></a><p class="title"><b>Example 27.11. data read from file (<code class="filename">qrexample08.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 8 : QR Barcode with data read from file</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$readFromFilename</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">qr-input.txt</span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder and let the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> decide a suitable QR version and error level</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code">=</span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">=</span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size (quite big)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> .. send the barcode back to the browser for the data in the file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">StrokeFromFile</span><span class="hl-brackets">(</span><span class="hl-var">$readFromFilename</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample08"></a><p class="title"><b>Figure 27.18. data read from file <code class="uri"><a class="uri" href="example_src/qrexample08.html" target="_top">(<code class="filename">qrexample08.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample08.png" alt="data read from file (qrexample08.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 7 - Adjusting colors"><div class="titlepage"><div><div><h3 class="title"><a name="id2619074"></a>Example 7 - Adjusting colors</h3></div></div></div>
|
||
|
||
<p>QR Barcode with data read from file and different colors</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample09"></a><p class="title"><b>Example 27.12. (<code class="filename">qrexample09.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 9 : QR Barcode with data read from file and different colors</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/jpgraph.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$readFromFilename</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">qr-input.txt</span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder and let the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> decide a suitable QR version and error level</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size (quite big)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use blue and white colors instead</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">navy</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> .. send the barcode back to the browser for the data in the file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">StrokeFromFile</span><span class="hl-brackets">(</span><span class="hl-var">$readFromFilename</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample09"></a><p class="title"><b>Figure 27.19. <code class="uri"><a class="uri" href="example_src/qrexample09.html" target="_top">(<code class="filename">qrexample09.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample09.png" alt="(qrexample09.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 8 - Setting error correction level"><div class="titlepage"><div><div><h3 class="title"><a name="id2619119"></a>Example 8 - Setting error correction level</h3></div></div></div>
|
||
|
||
<p>Specified error correction level</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample10"></a><p class="title"><b>Example 27.13. Specified error correction level (<code class="filename">qrexample10.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 10 : Specified error correction level</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">ABCDEFGH01234567</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = -</span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1 = Let the library decide version (same as default)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$corrlevel</span><span class="hl-code"> = </span><span class="hl-identifier">QRCapacity</span><span class="hl-code">::</span><span class="hl-identifier">ErrH</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Error correction level H (Highest possible)</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder using the specified</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> QR version and error correction</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$corrlevel</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_IMAGE</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set color</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetColor</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">brown</span><span class="hl-quotes">'</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string">white</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break"> </p><div class="figure"><a name="fig.qrexample10"></a><p class="title"><b>Figure 27.20. Specified error correction level <code class="uri"><a class="uri" href="example_src/qrexample10.html" target="_top">(<code class="filename">qrexample10.php</code>)</a></code> </b></p><div class="figure-contents"> <span class="inlinemediaobject"><img src="images/qrexample10.png" alt="Specified error correction level (qrexample10.php)"></span> </div></div><p><br class="figure-break">
|
||
</p>
|
||
</div>
|
||
<div class="sect2" title="Example 9 - Generating ASCII output"><div class="titlepage"><div><div><h3 class="title"><a name="id2619201"></a>Example 9 - Generating ASCII output</h3></div></div></div>
|
||
|
||
<p>Using the ASCII backend</p>
|
||
<p>
|
||
</p><div class="example"><a name="example.qrexample12"></a><p class="title"><b>Example 27.14. Using the ASCII backend (<code class="filename">qrexample12.php</code>) </b></p><div class="example-contents"> <div class="hl-main"><table class="hl-table" width="100%"><tr><td class="hl-gutter" align="right" valign="top"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags"><?php</span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Include the library</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-reserved">require_once</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/QR/qrencoder.inc.php</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Example 11 : Generate postscript output</span><span class="hl-comment"></span><span class="hl-code">
|
||
|
||
</span><span class="hl-var">$data</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">ABCDEFGH01234567</span><span class="hl-quotes">'</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Data to be encoded</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$version</span><span class="hl-code"> = -</span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1 = Let the library decide version (same as default)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$corrlevel</span><span class="hl-code"> = </span><span class="hl-identifier">QRCapacity</span><span class="hl-code">::</span><span class="hl-identifier">ErrH</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> Error correction level H (Highest possible)</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$modulewidth</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Create a new instance of the encoder using the specified</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> QR version and error correction</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$encoder</span><span class="hl-code"> = </span><span class="hl-reserved">new</span><span class="hl-code"> </span><span class="hl-identifier">QREncoder</span><span class="hl-brackets">(</span><span class="hl-var">$version</span><span class="hl-code">,</span><span class="hl-var">$corrlevel</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Use the image backend</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code"> = </span><span class="hl-identifier">QRCodeBackendFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-var">$encoder</span><span class="hl-code">, </span><span class="hl-identifier">BACKEND_ASCII</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Set the module size</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">SetModuleWidth</span><span class="hl-brackets">(</span><span class="hl-var">$modulewidth</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-comment">//</span><span class="hl-comment"> Store the barcode in the specifed file</span><span class="hl-comment"></span><span class="hl-code">
|
||
</span><span class="hl-var">$ps_str</span><span class="hl-code"> = </span><span class="hl-var">$backend</span><span class="hl-code">-></span><span class="hl-identifier">Stroke</span><span class="hl-brackets">(</span><span class="hl-var">$data</span><span class="hl-brackets">)</span><span class="hl-code">;
|
||
|
||
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string"><pre></span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$ps_str</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string"></pre></span><span class="hl-quotes">'</span><span class="hl-code">;
|
||
</span><span class="hl-inlinetags">?></span></pre></td></tr></table></div></div></div><p><br class="example-break">
|
||
</p>
|
||
<div class="figure"><a name="id2619239"></a><p class="title"><b>Figure 27.21. QR With ASCII rendering</b></p><div class="figure-contents">
|
||
|
||
<div class="mediaobject"><img src="images/qr-ASCII.png" alt="QR With ASCII rendering"></div>
|
||
</div></div><br class="figure-break">
|
||
</div>
|
||
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"><a accesskey="u" href="ch27.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|