samt/barcode

Unhandled error and empty image

parth0595 opened this issue · 6 comments

var barcode = require('barcode');
var path = require('path');
var code128 = barcode('code128', {
    data: "r1001-20160906-0001",
    width: 500,
    height: 100,
});
var outfile = path.join(__dirname, 'imgs', 'mm.png');
code128.saveImage(outfile, function (err) {

    if (err) throw err;
    console.log('File has been written!');

});

this is what I get.

throw er; // Unhandled 'error' event
      ^
Error: spawn gm ENOENT
    at exports._errnoException (util.js:1050:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

It generates an empty image .

Found the solution. it works fine after installing graphics magic. @samt Is there any way we can use labels on top of the barcode generated?

for Linux (Ubuntu) user, you can solve this problem by running this in terminal
sudo npm install --save gm
sudo apt install graphicsmagick
if the error continue :
sudo npm install --save graphicsmagick
sudo npm install --save imagemagick

Is there any way to solve in windows?? As I have already installed graphicsMagick.

Its solved... @ripu502

@ripu502 For windows you need to install graphicsMagick application from official site http://www.graphicsmagick.org/ and restart your computer