Skip to content

Commit 1eb2da0

Browse files
committed
Improve readme for v2
1 parent b01dcfe commit 1eb2da0

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

Readme.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ This is an easy to use, non-bloated, framework independent, barcode generator in
55

66
It creates SVG, PNG, JPG and HTML images, from the most used 1D barcode standards.
77

8-
*The codebase is largely from the [TCPDF barcode generator](https://github.com/tecnickcom/TCPDF) by Nicola Asuni. This code is therefor licensed under LGPLv3.*
8+
*The codebase is based on the [TCPDF barcode generator](https://github.com/tecnickcom/TCPDF) by Nicola Asuni. This code is therefor licensed under LGPLv3.*
9+
10+
## No support for...
11+
We do not support any 2D barcodes, like QR codes. We also only generate the 'bars' part of a barcode. If you want text of the code below the barcode, you could add it later to the output of this package.
912

1013
## Installation
1114
Install through [composer](https://getcomposer.org/doc/00-intro.md):
@@ -20,16 +23,31 @@ If you want to generate PNG or JPG images, you need the GD library or Imagick in
2023
Initiate the barcode generator for the output you want, then call the ->getBarcode() routine as many times as you want.
2124

2225
```php
26+
<?php
27+
require 'vendor/autoload.php';
28+
29+
// This will output the barcode as HTML output to display in the browser
2330
$generator = new Picqer\Barcode\BarcodeGeneratorHTML();
2431
echo $generator->getBarcode('081231723897', $generator::TYPE_CODE_128);
2532
```
2633

27-
The ->getBarcode() routine accepts the following:
28-
- $code Data for the barcode
29-
- $type Type of barcode, use the constants defined in the class
30-
- $widthFactor Width is based on the length of the data, with this factor you can make the barcode bars wider than default
31-
- $totalHeight The total height of the barcode
32-
- $color Hex code of the foreground color
34+
The `getBarcode()` method accepts the following parameters:
35+
- `$barcode` String needed to encode in the barcode
36+
- `$type` Type of barcode, use the constants defined in the class
37+
- `$widthFactor` Width is based on the length of the data, with this factor you can make the barcode bars wider than default
38+
- `$height` The total height of the barcode in pixels
39+
- `$foregroundColor` Hex code as string, or array of RGB, of the colors of the bars (the foreground color)
40+
41+
```php
42+
<?php
43+
44+
require 'vendor/autoload.php';
45+
46+
$redColor = [255, 0, 0];
47+
48+
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
49+
file_put_contents('barcode.png', $generator->getBarcode('081231723897', $generator::TYPE_CODE_128, 3, 50, $redColor));
50+
```
3351

3452
## Image types
3553
```php
@@ -39,7 +57,11 @@ $generatorJPG = new Picqer\Barcode\BarcodeGeneratorJPG();
3957
$generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML();
4058
```
4159

42-
## Accepted types
60+
## Accepted barcode types
61+
These barcode types are supported. All types support different character sets or have mandatory lengths. Please see wikipedia for supported chars and lengths per type.
62+
63+
Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner support, variable length and most chars supported.
64+
4365
- TYPE_CODE_39
4466
- TYPE_CODE_39_CHECKSUM
4567
- TYPE_CODE_39E
@@ -73,10 +95,26 @@ $generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML();
7395

7496
[See example images for all supported barcode types](examples.md)
7597

98+
## A note about PNG and JPG images
99+
If you want to use PNG or JPG images, you need to install [Imagick](https://www.php.net/manual/en/intro.imagick.php) or the [GD library](https://www.php.net/manual/en/intro.image.php). This package will use Imagick if that is installed, or fall back to GD. If you have both installed but you want a specific method, you can use `$generator->useGd()` or `$generator->useImagick()` to force your preference.
100+
101+
We use Imagick as standard because the size of the output is factor 10 smaller.
102+
76103
## Examples
77-
Embedded PNG image in HTML:
78104

105+
### Embedded PNG image in HTML
79106
```php
80-
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
107+
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
81108
echo '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode('081231723897', $generator::TYPE_CODE_128)) . '">';
82109
```
110+
111+
### Save JPG barcode to disk
112+
```php
113+
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
114+
file_put_contents('barcode.jpg', $generator->getBarcode('081231723897', $generator::TYPE_CODABAR));
115+
```
116+
117+
### Oneliner SVG output to disk
118+
```php
119+
file_put_contents('barcode.svg', (new Picqer\Barcode\BarcodeGeneratorSVG())->getBarcode('6825ME601', Picqer\Barcode\BarcodeGeneratorSVG::TYPE_KIX));
120+
```

0 commit comments

Comments
 (0)