Skip to content

Instantly share code, notes, and snippets.

@moriczgergo moriczgergo/png2hqr.js
Last active Jan 14, 2019

Embed
What would you like to do?
png2hqr - creates hackmud QR from .png
#!/usr/bin/env node
var fs = require('fs');
var PNG = require('pngjs').PNG;
fs.createReadStream(process.argv[2])
.pipe(new PNG())
.on('parsed', function() {
var buffer = "";
for (var y = 0; y < this.height; y += 2) {
for (var x = 0; x < this.width; x++) {
var idxTop = (this.width * y + x) << 2;
var idxBot = (this.width * (y+1) + x) << 2;
var topBlack = this.data[idxTop] == 0 && this.data[idxTop+1] == 0 && this.data[idxTop+2] == 0;
var botBlack = this.data[idxBot] == 0 && this.data[idxBot+1] == 0 && this.data[idxBot+2] == 0;
if (topBlack && botBlack) buffer += "";
else if (topBlack) buffer += "";
else if (botBlack) buffer += "";
else buffer += " ";
}
buffer += "\n"
}
console.log(buffer);
})
Use size 1. (1 dot = 1 pixel)
Use ECC H QR codes.
Provide path to image as argument.
npm i -s pngjs
Good generator site: https://qrcode.tec-it.com/en
Settings: DPI should be 96, Error Correction Level High, Quiet Zone 0, Size Small. You will need to resize it to it's original size/3 in an image editing program. (use nearest neighbor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.