/barcode-generator

Barcode Generator allows you to generate a wide variety of 1d & 2d codes

Primary LanguageJavaScriptMIT LicenseMIT

Barcode Generator

Do you need to generate 1d or 2d codes? This project can generate a lot of them.

Installation and run

  1. Clone this repository
$ git clone https://github.com/padiazg/barcode-generator.git
  1. Change to the folder just created
$ cd barcode-generator
  1. Install dependencies
$ npm install
  1. Run
node index.js

Running it on a container

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

Examples:

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

Parameters

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 to png.

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 say EAN-13 as example) and search the Encoder: value (ean13 in this example). This value is what we need pass as bcid'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.

Supported code types

There is an extensive list of the code types that you can generate in the supported-code-types file.

Live demo

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.

Acknowledgment

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

Contact

Please use Github issue tracker for filling bugs or feature requests. For direct contact drop me a message to padiazg@gmail.com

License

Barcode Generator is licensed under MIT License.