Skip to content

Commit

Permalink
Add option to remove padding character from EAN-13
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaRGB committed Oct 3, 2018
1 parent 9d5f7b9 commit 010bb1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion barcode-readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ <h4>Options:</h4>
<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>
Expand Down
10 changes: 6 additions & 4 deletions barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,7 +216,9 @@ private function dispatch_encode($symbology, $data, $options) {
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);
Expand Down Expand Up @@ -720,7 +722,7 @@ private function upc_e_encode($data) {
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). */
Expand Down Expand Up @@ -788,7 +790,7 @@ private function ean_13_encode($data) {
);
$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);
Expand Down

0 comments on commit 010bb1e

Please sign in to comment.