xref: /plugin/statdisplay/vendor/szymach/c-pchart/resources/doc/barcode_128.md (revision 03cdebb71906645bc452782ad23f052261c2cb18)
1# Drawing a barcode 128
2
3[Reference](http://wiki.pchart.net/doc.barcode128.pBarcode128.html)
4
5```php
6require '/path/to/your/vendor/autoload.php';
7
8use CpChart\Barcode\Barcode128;
9use CpChart\Image;
10
11/* Create the Image object */
12$image = new Image(700, 230);
13
14/* Draw the background */
15$image->drawFilledRectangle(0, 0, 700, 230, [
16    "R" => 170,
17    "G" => 183,
18    "B" => 87,
19    "Dash" => 1,
20    "DashR" => 190,
21    "DashG" => 203,
22    "DashB" => 107
23]);
24
25/* Overlay with a gradient */
26$image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, [
27    "StartR" => 219,
28    "StartG" => 231,
29    "StartB" => 139,
30    "EndR" => 1,
31    "EndG" => 138,
32    "EndB" => 68,
33    "Alpha" => 50
34]);
35$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
36    "StartR" => 0,
37    "StartG" => 0,
38    "StartB" => 0,
39    "EndR" => 50,
40    "EndG" => 50,
41    "EndB" => 50,
42    "Alpha" => 80
43]);
44
45/* Draw the top bar */
46$image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, [
47    "StartR" => 0,
48    "StartG" => 0,
49    "StartB" => 0,
50    "EndR" => 50,
51    "EndG" => 50,
52    "EndB" => 50,
53    "Alpha" => 100
54]);
55$image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
56$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
57$image->drawText(10, 13, "Barcode 128 - Add barcode to your pictures", ["R" => 255, "G" => 255, "B" => 255]);
58
59/* Create the barcode 128 object */
60$barcodeChart = new Barcode128();
61
62/* Draw a simple barcode */
63$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
64$barcodeChart->draw($image, "pChart Rocks!", 50, 50, ["ShowLegend" => true, "DrawArea" => true]);
65
66/* Draw a rotated barcode */
67$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
68$barcodeChart->draw($image, "Turn me on", 650, 50, ["ShowLegend" => true, "DrawArea" => true, "Angle" => 90]);
69
70/* Draw a rotated barcode */
71$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
72$barcodeChart->draw($image, "Do what you want !", 290, 140, [
73    "R" => 255,
74    "G" => 255,
75    "B" => 255,
76    "AreaR" => 150,
77    "AreaG" => 30,
78    "AreaB" => 27,
79    "ShowLegend" => true,
80    "DrawArea" => true,
81    "Angle" => 350,
82    "AreaBorderR" => 70,
83    "AreaBorderG" => 20,
84    "AreaBorderB" => 20
85]);
86
87/* Render the picture */
88$image->autoOutput("example.barcode128.png");
89```
90