GithubHelp home page GithubHelp logo

barcode's Introduction

barcode generator Build Status

Generate 1D and 2D barcodes

Supported 1D types

Supported 2D types

Requirements

Installing

npm install barcode

Usage

Set it up and specify your type and options. The following 3 are the only required ones.

var barcode = require('barcode');
var code39 = barcode('code39', {
	data: "it works",
	width: 400,
	height: 100,
});

Next choose from the three methods below how you want to output your barcode.

Stream

Get a stream of the final image data. you can collect this and save out a new PNG (default type), pipe it elsewhere, or save it to a CDN.

code39.getStream(function (err, readStream) {
	if (err) throw err;

	// 'readStream' is an instance of ReadableStream
	readStream.pipe(CdnWriteStream);
});

File to disk

Save an image out to the file system, pretty simple. Just be sure to specify your outfile.

var outfile = path.join(__dirname, 'imgs', 'mycode.png')
code39.saveImage(outfile, function (err) {
	if (err) throw err;

	console.log('File has been written!');
});

Base64 encoded img src

Often times, barcodes are single use for a single print or whatever. With this method, we can create one on the fly and just send the base64 encoded image to the browser through the HTML.

code39.getBase64(function (err, imgsrc) {
	if (err) throw err;

	// if we're using HTTP or another framework
	res.end('<img src="' + imgsrc + '">');
});

Refactor

Much of the underlying code for the generation is being rewritten, however the API will remain the same. As a rule, anything new will have to be testable.

Things todo:

  • Move all checksums and ECC to a module in lib/utils
  • Use the new barcode generation class: Barcode2D.js
  • Remove uses of Barcode1D and in-place image generation
  • Create separate functions for generating sequences

In the future:

  • Abstract drawing to be able to draw with gm or output html (bars with css or canvas)

License

The MIT License (MIT)

barcode's People

Contributors

samt avatar nishit-rapidops avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.