Skip to content

Commit bbe5415

Browse files
committed
Update readme
1 parent f20b1ef commit bbe5415

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

Readme.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ $renderer->setForegroundColor($colorRed);
5858
file_put_contents('barcode.png', $renderer->render($barcode, 3, 50));
5959
```
6060

61-
## Image types
61+
## Image renderers
62+
These are the available renderers:
6263
```php
6364
$renderer = new Picqer\Barcode\Renderers\SvgRenderer(); // Vector based SVG
6465
$renderer = new Picqer\Barcode\Renderers\PngRenderer(); // Pixel based PNG
@@ -67,6 +68,51 @@ $renderer = new Picqer\Barcode\Renderers\HtmlRenderer(); // Pixel based HTML
6768
$renderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer(); // Vector based HTML (full 'page' width and height)
6869
```
6970

71+
Each renderer has their own options. Only the barcode is required, the rest is optional. Here are all the options for each renderers:
72+
73+
### SVG
74+
```php
75+
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
76+
$renderer->setForegroundColor('red'); // Give a color for the bars, the background is always white
77+
$renderer->setSvgType($renderer::TYPE_SVG_INLINE); // Changes the output to be used inline inside HTML documents, instead of a standalone SVG image (default)
78+
$renderer->setSvgType($renderer::TYPE_SVG_STANDALONE); // If you want to force the default, create a stand alone SVG image
79+
80+
$renderer->render($barcode, 450.20, 75); // Width and height support floats
81+
````
82+
83+
### PNG + JPG
84+
All options for PNG and JPG are the same.
85+
```php
86+
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
87+
$renderer->setForegroundColor([255, 0, 0]); // Give a color for the bars, the background is always white. Give it as 3 times 0-255 values for red, green and blue.
88+
$renderer->useGd(); // If you have Imagick and GD installed, but want to use GD
89+
$renderer->useImagick(); // If you have Imagick and GD installed, but want to use Imagick
90+
$renderer->render($barcode, 5, 40); // Width factor (how many pixel wide every bar is), and the height in pixels
91+
````
92+
93+
### HTML
94+
Gives HTML to use inline in a full HTML document.
95+
```php
96+
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
97+
$renderer->setForegroundColor('red'); // Give a color for the bars, the background is always white
98+
99+
$renderer->render($barcode, 450.20, 75); // Width and height support floats
100+
````
101+
102+
### Dynamic HTML
103+
Give HTML here the barcode is using the full width and height, to put inside a container/div that has a fixed size.
104+
```php
105+
$renderer = new Picqer\Barcode\Renderers\DynamicHtmlRenderer();
106+
$renderer->setForegroundColor('red'); // Give a color for the bars, the background is always white
107+
108+
$renderer->render($barcode);
109+
````
110+
111+
You can put the rendered HTML inside a div like this:
112+
```html
113+
<div style="width: 400px; height: 75px"><?php echo $renderedBarcode; ?></div>
114+
```
115+
70116
## Accepted barcode types
71117
These barcode types are supported. All types support different character sets and some have mandatory lengths. Please see wikipedia for supported chars and lengths per type.
72118

src/Renderers/JpgRenderer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function createImagickImageObject(int $width, int $height): Imagick
1414
return $image;
1515
}
1616

17-
protected function generateGdImage($image)
17+
protected function generateGdImage($image): void
1818
{
1919
\imagejpeg($image);
2020
\imagedestroy($image);

src/Renderers/PngRenderer.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public function __construct()
3232
/**
3333
* Force the use of Imagick image extension
3434
*/
35-
public function useImagick()
35+
public function useImagick(): void
3636
{
3737
$this->useImagick = true;
3838
}
3939

4040
/**
4141
* Force the use of the GD image library
4242
*/
43-
public function useGd()
43+
public function useGd(): void
4444
{
4545
$this->useImagick = false;
4646
}
@@ -81,14 +81,14 @@ public function render(Barcode $barcode, int $widthFactor = 2, int $height = 30)
8181
$image = $this->createImagickImageObject($width, $height);
8282
$image->drawImage($imagickBarsShape);
8383
return $image->getImageBlob();
84+
} else {
85+
ob_start();
86+
$this->generateGdImage($image);
87+
return ob_get_clean();
8488
}
85-
86-
ob_start();
87-
$this->generateGdImage($image);
88-
return ob_get_clean();
8989
}
9090

91-
public function setForegroundColor(array $color)
91+
public function setForegroundColor(array $color): void
9292
{
9393
$this->foregroundColor = $color;
9494
}
@@ -110,7 +110,7 @@ protected function createImagickImageObject(int $width, int $height): Imagick
110110
return $image;
111111
}
112112

113-
protected function generateGdImage($image)
113+
protected function generateGdImage($image): void
114114
{
115115
\imagepng($image);
116116
\imagedestroy($image);

0 commit comments

Comments
 (0)