This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/includes/jpgraph/docs/chunkhtml/example_src/datamatrix_ex6.html
2011-05-28 19:51:52 +10:00

67 lines
7.1 KiB
HTML

<div style="font-weight: bold;margin-left:15px;">datamatrix_ex6.php</div><link rel="stylesheet" href="../phphl.css" type="text/css"><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
30
31
32
33
</pre></td><td class="hl-main" valign="top"><pre><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-reserved">require_once</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">jpgraph/datamatrix/datamatrix.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">This is a datamatrix symbol</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-var">$outputfile</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">dm_ex6.png</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Create and set parameters for the encoder</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-identifier">DatamatrixFactory</span><span class="hl-code">::</span><span class="hl-identifier">Create</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$encoder</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetEncoding</span><span class="hl-brackets">(</span><span class="hl-identifier">ENCODING_TEXT</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Create the image backend (default)</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">DatamatrixBackendFactory</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-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</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-var">$backend</span><span class="hl-code">-&gt;</span><span class="hl-identifier">SetQuietZone</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> Set other than default colors (one, zero, background)</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</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"> Create the barcode from the given data string and write to output file</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$dir</span><span class="hl-code"> = </span><span class="hl-identifier">dirname</span><span class="hl-brackets">(</span><span class="hl-reserved">__FILE__</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$file</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">&lt;span style=&quot;font-weight:bold;&quot;&gt;&quot;</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$dir</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">/</span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$outputfile</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">&quot;&lt;/span&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-reserved">try</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
</span><span class="hl-var">$backend</span><span class="hl-code">-&gt;</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">$outputfile</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">Barcode sucessfully written to file: </span><span class="hl-quotes">'</span><span class="hl-code">.</span><span class="hl-var">$file</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code"> </span><span class="hl-reserved">catch</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">Exception</span><span class="hl-code"> </span><span class="hl-var">$e</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">$errstr</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetMessage</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-var">$errcode</span><span class="hl-code"> = </span><span class="hl-var">$e</span><span class="hl-code">-&gt;</span><span class="hl-identifier">GetCode</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">&quot;</span><span class="hl-string">Failed writing file: </span><span class="hl-quotes">&quot;</span><span class="hl-code">.</span><span class="hl-var">$file</span><span class="hl-code">.</span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">Datamatrix error (</span><span class="hl-var">$errcode</span><span class="hl-string">). Message: </span><span class="hl-var">$errstr</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></pre></td></tr></table></div>