Do you need to generate 1d or 2d codes? This project can generate a lot of them.
- Clone this repository
$ git clone https://github.com/padiazg/barcode-generator.git
- Change to the folder just created
$ cd barcode-generator
- Install dependencies
$ npm install
- Run
node index.js
Build the image
$ docker build -t your_dockerhub_id/barcode-generator .
Run it in a single container
$ docker run -d -p 3000:3000 --name barcode-generator padiazg/barcode-generator
Run it as a Docker service, can be scaled You need Swarm enabled to run services
$ docker service create --name barcode-generator --publish 3000:3000 padiazg/barcode-generator
Parameters must be passed as query string:
Example:
# ean13, white background, 2px of padding, show text
$ curl "http://localhost:3000?bcid=ean13&text=123456789012&backgroundcolor=FFFFFF&paddingwidth=2&paddingheight=2&includetext=true" --output ean13.png
# QR code, white background, 2px of padding
$ curl "http://localhost:3000?bcid=qrcode&text=Hello+world!&backgroundcolor=FFFFFF&paddingwidth=2&paddingheight=2" --output qrcode.png
Specific from this project:
- base64: Optional, not part of the modules parameters. Tells the function that we want the ouput encoded in base64. Defaults tu
false
. - format: Optional, not part of the modules parameters. By default a PNG image is generated. If you need a JPG image set this parameter to
jpg
. Defaults topng
.
Specific from bwip-js
-
bcid: The requested code. required
Look here a reference of which codes can be generated.
Search the symbol you are interested in, go into the page (Ex: let´s sayEAN-13
as example) and search theEncoder:
value (ean13 in this example). This value is what we need pass asbcid
's value. -
text: The value to represent. required. Look at the reference to know what's the format for each symbol.
-
scaleX: The x-axis scaling factor. Must be an integer > 0. Default is 2.
-
scaleY: The y-axis scaling factor. Must be an integer > 0. Default is scaleX.
-
scale: Sets both the x-axis and y-axis scaling factors. Must be an integer > 0.
-
rotate: Allows rotating the image to one of the four orthogonal orientations. A string value. Must be one of:
- "N" : Normal (not rotated). The default.
- "R" : Clockwise (right) 90 degree rotation.
- "L" : Counter-clockwise (left) 90 degree rotation.
- "I" : Inverted 180 degree rotation.
-
paddingwidth: Sets the left and right padding (in points/pixels) around the rendered barcode. Rotates and scales with the image.
-
paddingheight: Sets the top and bottom padding (in points/pixels) around the rendered barcode. Rotates and scales with the image.
-
monochrome: Sets the human-readable text to render in monochrome. Boolean true or false. Default is false which renders 256-level gray-scale anti-aliased text.
There are more options specific from BWIPP, and they are documented in the BWIPP wiki. You need to consult there to determine what options are available for each barcode type.
There is an extensive list of the code types that you can generate in the supported-code-types file.
Once you have a running instance you can go to http://your-server-url/live
and see a live demo where you can generate any one of the codes supported.
This project uses bwip-js, which is a translation to native JavaScript of the amazing code provided in Barcode Writer in Pure PostScript. The translated code can run on any modern browser or JavaScript-based server framework.
Helper functions inspired on this article
Please use Github issue tracker for filling bugs or feature requests. For direct contact drop me a message to [email protected]
Barcode Generator is licensed under MIT License.