mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 02:39:59 +01:00
* Added options startingX and startingY in Add-Qr Module * requeste changes * Fixing Qr Code at the end when not fit in the image Co-authored-by: Rishabh Shukla <42492389+blurry-x-face@users.noreply.github.com>
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
const pixelSetter = require('../../util/pixelSetter.js'),
|
|
getPixels = require('get-pixels'),
|
|
QRCode = require('qrcode');
|
|
module.exports = exports = function (options, pixels, oldPixels, cb) {
|
|
|
|
QRCode.toDataURL(options.qrCodeString, {width: options.size, scale: 1}, function (error, url) {
|
|
getPixels(url, function (err, qrPixels) {
|
|
if (err) {
|
|
console.log('get-pixels error: ', err);
|
|
}
|
|
|
|
const width = oldPixels.shape[0],
|
|
height = oldPixels.shape[1];
|
|
|
|
const xe = Math.min(options.startingX, width - options.size), // Starting pixel coordinates
|
|
ye = Math.min(options.startingY, height - options.size);
|
|
|
|
for (let x = xe; x < Math.min(xe + options.size, width); x++) {
|
|
for (let y = ye; y < Math.min(ye + options.size, height); y++) {
|
|
pixelSetter(
|
|
x,
|
|
y,
|
|
[
|
|
qrPixels.get(x - xe, y - ye, 0),
|
|
qrPixels.get(x - xe, y - ye, 1),
|
|
qrPixels.get(x - xe, y - ye, 2),
|
|
qrPixels.get(x - xe, y - ye, 3)
|
|
],
|
|
pixels
|
|
);
|
|
}
|
|
}
|
|
|
|
if(cb) cb();
|
|
});
|
|
});
|
|
};
|