Demonstration - Code 128
'use strict';
var http = require('http');
var barcodeBakeryCommon = require('barcode-bakery-common');
var barcodeBakery1D = require('barcode-bakery-1d');
var Color = barcodeBakeryCommon.Color;
var Drawing = barcodeBakeryCommon.Drawing;
var Font = barcodeBakeryCommon.Font;
var Label = barcodeBakeryCommon.Label;
http.createServer(function (request, response) {
var font = new Font('Arial', 18);
var colorFront = new Color(0, 0, 0);
var colorBack = new Color(255, 255, 255);
// Barcode Part
var code = new barcodeBakery1D.Code128();
code.setScale(2); // Resolution
code.setThickness(30); // Thickness
code.setForegroundColor(colorFront); // Color of bars
code.setBackgroundColor(colorBack); // Color of spaces
code.setFont(font); // Font
code.parse('a123');
// Drawing Part
var drawing = new Drawing(code, colorBack);
drawing.toBuffer(Drawing.IMG_FORMAT_PNG, function (err, buffer) {
response.writeHead(200, { "Content-Type": "image/png" });
response.end(buffer);
});
}).listen(8124);