From 010bb1ef926177bea51a7cea749ceb913353dacd Mon Sep 17 00:00:00 2001 From: "Rebecca G. Bettencourt" Date: Tue, 2 Oct 2018 22:08:10 -0700 Subject: [PATCH] Add option to remove padding character from EAN-13 --- LICENSE | 2 +- README.md | 14 +++++++------- barcode-readme.html | 4 +++- barcode.php | 10 ++++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/LICENSE b/LICENSE index 2f30740..4435b33 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index bd512da..3f755b7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/barcode-readme.html b/barcode-readme.html index ebbbb2d..c138abb 100644 --- a/barcode-readme.html +++ b/barcode-readme.html @@ -73,8 +73,10 @@ barcode.php?f=svg&s=qr&d=HELLO%20WORLD&sf=8&ms=r&md=0.8 upc-a
upc-e
- ean-13
ean-8
+ ean-13
+ ean-13-pad
+ ean-13-nopad
ean-128 diff --git a/barcode.php b/barcode.php index 384e670..b111501 100644 --- a/barcode.php +++ b/barcode.php @@ -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);