Skip to content

Commit 758488b

Browse files
committed
Initial commit
0 parents  commit 758488b

19 files changed

+3402
-0
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*]
2+
end_of_line = lf
3+
charset = utf-8
4+
5+
[*.php]
6+
indent_style = space
7+
indent_size = 4

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
### Code ###
3+
.vscode/*
4+
!.vscode/settings.json
5+
!.vscode/tasks.json
6+
!.vscode/launch.json
7+
!.vscode/extensions.json
8+
9+
### Composer ###
10+
composer.phar
11+
/vendor/
12+
13+
### PHP CS Fixer ###
14+
.php_cs.cache
15+
16+
### phpunit ###
17+
.phpunit.result.cache

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for XDebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9000
12+
},
13+
{
14+
"name": "Launch currently open script",
15+
"type": "php",
16+
"request": "launch",
17+
"program": "${file}",
18+
"cwd": "${fileDirname}",
19+
"port": 9000
20+
}
21+
]
22+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 hbgl
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# PHP Code 128 Encoder for Barcode Font
2+
3+
Encode text for use with Code 128 fonts such as [Libre Barcode 128](https://github.com/graphicore/librebarcode). The actual encoding is done by [tc-lib-barcode](https://github.com/tecnickcom/tc-lib-barcode).
4+
5+
## Installation
6+
7+
Install PHP Code 128 Encoder using [Composer](https://getcomposer.org/):
8+
9+
```
10+
composer require hbgl/php-code-128-encoder
11+
```
12+
13+
## Usage
14+
15+
```php
16+
<?php
17+
18+
require __DIR__ . '/../vendor/autoload.php';
19+
20+
use Hbgl\Barcode\Code128Encoder;
21+
22+
// Encode as Code 128.
23+
$encoded = Code128Encoder::encode('ABC123456DEF');
24+
assert ($encoded === 'ÌABCÇ,BXÈDEFqÎ');
25+
26+
// Only encode using Type A.
27+
$encodedA = Code128Encoder::encode('ABC123456DEF', 'A');
28+
assert ($encodedA === 'ËABC123456DEFLÎ');
29+
30+
// Only encode using Type B.
31+
$encodedB = Code128Encoder::encode('AcC123456DeF', 'B');
32+
assert ($encodedB === 'ÌAcC123456DeFSÎ');
33+
34+
// Only encode using Type C.
35+
$encodedC = Code128Encoder::encode('123456', 'C');
36+
assert ($encodedC === 'Í,BXLÎ');
37+
```
38+
39+
Use it together with the [Libre Barcode 128](https://github.com/graphicore/librebarcode) font to show a barcode on a webpage:
40+
41+
```php
42+
<?php
43+
44+
require __DIR__ . '/../vendor/autoload.php';
45+
46+
use Hbgl\Barcode\Code128Encoder;
47+
48+
$content = 'ABC123456DEF';
49+
$encoded = Code128Encoder::encode($content);
50+
51+
?>
52+
<!DOCTYPE html>
53+
<html>
54+
<head>
55+
<meta charset="utf-8">
56+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
57+
<title>Code 128</title>
58+
<link href="https://fonts.googleapis.com/css?family=Libre+Barcode+128&display=swap" rel="stylesheet">
59+
<style>
60+
body {
61+
text-align: center;
62+
}
63+
.code128 {
64+
padding: 3rem 1.5rem 0 1.5rem;
65+
font-family: "Libre Barcode 128";
66+
font-size: 3rem;
67+
transform: scaleY(1.5);
68+
}
69+
</style>
70+
</head>
71+
<body>
72+
<div class="code128"><?= htmlspecialchars($encoded) ?></div>
73+
<div><?= htmlspecialchars($content) ?></div>
74+
</body>
75+
</html>
76+
```
77+
78+
Result:
79+
80+
![Barcode Result](assets/barcode.png)
81+
82+
## License
83+
84+
This library is licensed under the [MIT license](https://opensource.org/licenses/MIT).

assets/barcode.png

837 Bytes
Loading

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "hbgl/php-code-128-encoder",
3+
"description": "Encode text for use with Code 128 fonts such as Libre Barcode 128.",
4+
"homepage": "https://github.com/hbgl/php-code-128-encoder",
5+
"type": "library",
6+
"license": "MIT",
7+
"keywords": [
8+
"Barcode",
9+
"Barcode Font",
10+
"Code 128",
11+
"Libre Barcode",
12+
"Encoder"
13+
],
14+
"require": {
15+
"tecnickcom/tc-lib-barcode": "1.15.14"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "^8.3",
19+
"phpstan/phpstan": "^0.11.16"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Hbgl\\Barcode\\": "src/"
24+
}
25+
},
26+
"autoload-dev": {
27+
"psr-4": {
28+
"Hbgl\\Barcode\\Tests\\": "tests/"
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)