Skip to content

Instantly share code, notes, and snippets.

@fxp
Created December 27, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxp/285c17a242f9bc4d07a396d14b0561b3 to your computer and use it in GitHub Desktop.
Save fxp/285c17a242f9bc4d07a396d14b0561b3 to your computer and use it in GitHub Desktop.
generate bar code
const bwipjs = require('bwip-js');
const fs = require('fs');
async function genImgs() {
for (let i = 1; i < 500 ; i++) {
const stream = fs.createWriteStream("./" + i + ".png");
let buf = await bwipjs.toBuffer({
bcid: 'code128',
text: '' + i,
scale: 3,
height: 10,
includetext: true,
textxalign: 'center',
dpi:300
});
await stream.write(buf);
}
}
genImgs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment