source: trunk/client/modules/Elezioni/grafici/barcode/demoapp/barcode_image.php@ 360

Last change on this file since 360 was 266, checked in by roby, 6 years ago
File size: 2.1 KB
Line 
1<?php
2require_once "jpgraph/jpgraph.php";
3require_once "jpgraph/jpgraph_canvas.php";
4require_once "jpgraph/jpgraph_barcode.php";
5
6$params = array(
7 array('code',1),array('data',''),array('modwidth',1),array('info',false),
8 array('notext',false),array('checksum',false),array('showframe',false),
9 array('vertical',false) , array('backend','IMAGE'), array('file',''),
10 array('scale',1), array('height',70), array('pswidth','') );
11
12$n=count($params);
13for($i=0; $i < $n; ++$i ) {
14 $v = $params[$i][0];
15 if( empty($_GET[$params[$i][0]]) ) {
16 $$v = $params[$i][1];
17 }
18 else
19 $$v = $_GET[$params[$i][0]];
20}
21
22if( $modwidth < 1 || $modwidth > 5 ) {
23 echo "<h4>Module width must be between 1 and 5 pixels</h4>";
24}
25elseif( $data==="" ) {
26 echo "<h3>Please enter data to be encoded, select symbology and press 'Ok'.</h3>";
27 echo "<i>Note: Data must be valid for the choosen encoding.</i>";
28}
29elseif( $code==-1 ) {
30 echo "<h4>No code symbology selected.</h4>";
31}
32elseif( $height < 10 || $height > 500 ) {
33 echo "<h4> Height must be in range [10, 500]</h4>";
34}
35elseif( $scale < 0.1 || $scale > 15 ) {
36 echo "<h4> Scale must be in range [0.1, 15]</h4>";
37}
38else {
39 if( $code==20 ) {
40 $encoder = BarcodeFactory::Create(6);
41 $encoder->UseExtended();
42 }
43 else {
44 $encoder = BarcodeFactory::Create($code);
45 }
46 $b = $backend=='EPS' ? 'PS' : $backend;
47 $b = substr($backend,0,5) == 'IMAGE' ? 'IMAGE' : $b;
48 $e = BackendFactory::Create($b,$encoder);
49 if( substr($backend,0,5) == 'IMAGE' ) {
50 if( substr($backend,5,1) == 'J' )
51 $e->SetImgFormat('JPEG');
52 }
53 if( $e ) {
54 if( $backend == 'EPS' )
55 $e->SetEPS();
56 if( $pswidth!='' )
57 $modwidth = $pswidth;
58 $e->SetModuleWidth($modwidth);
59 $e->AddChecksum($checksum);
60 $e->NoText($notext);
61 $e->SetScale($scale);
62 $e->SetVertical($vertical);
63 $e->ShowFrame($showframe);
64 $e->SetHeight($height);
65 $r = $e->Stroke($data,$file,$info,$info);
66 if( $r )
67 echo nl2br(htmlspecialchars($r));
68 if( $file != '' )
69 echo "<p>Wrote file $file.";
70 }
71 else
72 echo "<h3>Can't create choosen backend: $backend.</h3>";
73}
74
75?>
Note: See TracBrowser for help on using the repository browser.