5
0
mirror of https://github.com/cwinfo/php-barcode.git synced 2024-11-22 04:40:27 +00:00

Add option to remove padding character from EAN-13

This commit is contained in:
Rebecca G. Bettencourt 2018-10-02 22:08:10 -07:00
parent 9d5f7b97a7
commit 010bb1ef92
4 changed files with 17 additions and 13 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2016 Kreative Software
Copyright (c) 2016-2018 Kreative Software
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -50,13 +50,13 @@ barcode.php?f=svg&s=qr&d=HELLO%20WORLD&sf=8&ms=r&md=0.8
`s` - Symbology (type of barcode). One of:
```
upc-a code-39 qr dmtx
upc-e code-39-ascii qr-l dmtx-s
ean-13 code-93 qr-m dmtx-r
ean-8 code-93-ascii qr-q gs1-dmtx
ean-128 code-128 qr-h gs1-dmtx-s
codabar gs1-dmtx-r
itf
upc-a code-39 qr dmtx
upc-e code-39-ascii qr-l dmtx-s
ean-8 code-93 qr-m dmtx-r
ean-13 code-93-ascii qr-q gs1-dmtx
ean-13-pad code-128 qr-h gs1-dmtx-s
ean-13-nopad codabar gs1-dmtx-r
ean-128 itf
```
`d` - Data. For UPC or EAN, use `*` for missing digit. For Codabar, use `ABCD` or `ENT*` for start and stop characters. For QR, encode in Shift-JIS for kanji mode.

View File

@ -73,8 +73,10 @@ barcode.php?f=svg&s=qr&d=HELLO%20WORLD&sf=8&ms=r&md=0.8
<td>
<code>upc-a</code><br>
<code>upc-e</code><br>
<code>ean-13</code><br>
<code>ean-8</code><br>
<code>ean-13</code><br>
<code>ean-13-pad</code><br>
<code>ean-13-nopad</code><br>
<code>ean-128</code>
</td>
<td>

View File

@ -4,7 +4,7 @@
barcode.php - Generate barcodes from a single PHP file. MIT license.
Copyright (c) 2016 Kreative Software.
Copyright (c) 2016-2018 Kreative Software.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -216,7 +216,9 @@ class barcode_generator {
switch (strtolower(preg_replace('/[^A-Za-z0-9]/', '', $symbology))) {
case 'upca' : return $this->upc_a_encode($data);
case 'upce' : return $this->upc_e_encode($data);
case 'ean13' : return $this->ean_13_encode($data);
case 'ean13nopad' : return $this->ean_13_encode($data, ' ');
case 'ean13pad' : return $this->ean_13_encode($data, '>');
case 'ean13' : return $this->ean_13_encode($data, '>');
case 'ean8' : return $this->ean_8_encode($data);
case 'code39' : return $this->code_39_encode($data);
case 'code39ascii': return $this->code_39_ascii_encode($data);
@ -720,7 +722,7 @@ class barcode_generator {
return array('g' => 'l', 'b' => $blocks);
}
private function ean_13_encode($data) {
private function ean_13_encode($data, $pad) {
$data = $this->ean_13_normalize($data);
$blocks = array();
/* Quiet zone, start, first digit (as parity). */
@ -788,7 +790,7 @@ class barcode_generator {
);
$blocks[] = array(
'm' => array(array(0, 9, 0)),
'l' => array('>', 0.5, 2/3)
'l' => array($pad, 0.5, 2/3)
);
/* Return code. */
return array('g' => 'l', 'b' => $blocks);