mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 19:00:00 +01:00
Added options startingX and startingY in Add-Qr Module (#1520)
* 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>
This commit is contained in:
committed by
Jeffrey Warren
parent
2fba0d2074
commit
2b3e5a2915
@@ -1,14 +1,17 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash'),
|
||||||
|
parseCornerCoordinateInputs = require('../../util/ParseInputCoordinates');
|
||||||
module.exports = function AddQR(options, UI) {
|
module.exports = function AddQR(options, UI) {
|
||||||
|
|
||||||
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
|
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
|
||||||
options.size = options.size || defaults.size;
|
|
||||||
options.qrCodeString = options.qrCodeString || defaults.qrCodeString;
|
|
||||||
var output;
|
var output;
|
||||||
getPixels = require('get-pixels');
|
getPixels = require('get-pixels');
|
||||||
|
|
||||||
function draw(input, callback, progressObj) {
|
function draw(input, callback, progressObj) {
|
||||||
|
|
||||||
|
options.size = Number(options.size || defaults.size);
|
||||||
|
options.qrCodeString = options.qrCodeString || defaults.qrCodeString;
|
||||||
|
options.startingX = options.startingX || defaults.startingX;
|
||||||
|
options.startingY = options.startingY || defaults.startingY;
|
||||||
progressObj.stop(true);
|
progressObj.stop(true);
|
||||||
progressObj.overrideFlag = true;
|
progressObj.overrideFlag = true;
|
||||||
|
|
||||||
@@ -19,9 +22,21 @@ module.exports = function AddQR(options, UI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function extraManipulation(pixels, setRenderState, generateOutput) {
|
function extraManipulation(pixels, setRenderState, generateOutput) {
|
||||||
|
let iw = pixels.shape[0], // Width of Original Image
|
||||||
|
ih = pixels.shape[1]; // Height of Original Image
|
||||||
const oldPixels = _.cloneDeep(pixels);
|
const oldPixels = _.cloneDeep(pixels);
|
||||||
setRenderState(false); // Prevent rendering of final output image until extraManipulation completes.
|
setRenderState(false); // Prevent rendering of final output image until extraManipulation completes.
|
||||||
|
|
||||||
|
// Parse the inputs.
|
||||||
|
parseCornerCoordinateInputs({iw, ih},
|
||||||
|
{
|
||||||
|
startingX: { valInp: options.startingX, type: 'horizontal'},
|
||||||
|
startingY: { valInp: options.startingY, type: 'vertical' },
|
||||||
|
}, function(opt, cord){
|
||||||
|
options.startingX = Math.floor(cord.startingX.valInp);
|
||||||
|
options.startingY = Math.floor(cord.startingY.valInp);
|
||||||
|
});
|
||||||
|
|
||||||
require('./QR')(options, pixels, oldPixels, () => {
|
require('./QR')(options, pixels, oldPixels, () => {
|
||||||
setRenderState(true); // Allow rendering in the callback.
|
setRenderState(true); // Allow rendering in the callback.
|
||||||
generateOutput();
|
generateOutput();
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ module.exports = exports = function (options, pixels, oldPixels, cb) {
|
|||||||
const width = oldPixels.shape[0],
|
const width = oldPixels.shape[0],
|
||||||
height = oldPixels.shape[1];
|
height = oldPixels.shape[1];
|
||||||
|
|
||||||
const xe = width - options.size, // Starting pixel coordinates
|
const xe = Math.min(options.startingX, width - options.size), // Starting pixel coordinates
|
||||||
ye = height - options.size;
|
ye = Math.min(options.startingY, height - options.size);
|
||||||
|
|
||||||
for (let x = xe; x < width; x++) {
|
for (let x = xe; x < Math.min(xe + options.size, width); x++) {
|
||||||
for (let y = ye; y < height; y++) {
|
for (let y = ye; y < Math.min(ye + options.size, height); y++) {
|
||||||
pixelSetter(
|
pixelSetter(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
|||||||
@@ -12,6 +12,16 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"desc": "input string to generate QR code",
|
"desc": "input string to generate QR code",
|
||||||
"default": "https://github.com/publiclab/image-sequencer"
|
"default": "https://github.com/publiclab/image-sequencer"
|
||||||
|
},
|
||||||
|
"startingX": {
|
||||||
|
"type": "string",
|
||||||
|
"desc": "X-position (measured from left) from where QR starts",
|
||||||
|
"default": "0"
|
||||||
|
},
|
||||||
|
"startingY": {
|
||||||
|
"type": "string",
|
||||||
|
"desc": "Y-position (measured from top) from where QR starts",
|
||||||
|
"default": "0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#add-qr-module"
|
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#add-qr-module"
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user