From 0d730396953dfd8a608481a0ee5748d8c894c7be Mon Sep 17 00:00:00 2001 From: blurry-x-face Date: Sat, 1 Feb 2020 17:11:46 +0530 Subject: [PATCH 1/2] add support for transparent image overlay --- src/modules/Overlay/Module.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/Overlay/Module.js b/src/modules/Overlay/Module.js index 2bc72e084c..1ceb135077 100644 --- a/src/modules/Overlay/Module.js +++ b/src/modules/Overlay/Module.js @@ -47,20 +47,29 @@ module.exports = function Dynamic(options, UI, util) { function changePixel(r1, g1, b1, a1, x, y) { + var firstImagePixels = [r1, g1, b1, a1]; + // overlay var p = options.secondImagePixels; if (x >= options.x && x - options.x < p.shape[0] && y >= options.y - && y - options.y < p.shape[1]) - return [ + && y - options.y < p.shape[1]){ + + var secondImagePixels = [ p.get(x - options.x, y - options.y, 0), p.get(x - options.x, y - options.y, 1), p.get(x - options.x, y - options.y, 2), p.get(x - options.x, y - options.y, 3) ]; + + if(secondImagePixels[3] === 0) + return firstImagePixels; + else + return secondImagePixels; + } else - return [r1, g1, b1, a1]; + return firstImagePixels; } function output(image, datauri, mimetype, wasmSuccess) { From cc29e69b816cc9c8393d23ec1a1dea33d2ec4f1f Mon Sep 17 00:00:00 2001 From: blurry-x-face Date: Sun, 12 Jul 2020 20:51:22 +0530 Subject: [PATCH 2/2] replaced var for const/let --- src/modules/Overlay/Module.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/Overlay/Module.js b/src/modules/Overlay/Module.js index 1ceb135077..3f97753456 100644 --- a/src/modules/Overlay/Module.js +++ b/src/modules/Overlay/Module.js @@ -1,15 +1,17 @@ module.exports = function Dynamic(options, UI, util) { - var defaults = require('./../../util/getDefaults.js')(require('./info.json')); + const defaults = require('./../../util/getDefaults.js')(require('./info.json')); options.x = options.x || defaults.x; options.y = options.y || defaults.y; if(options.step.inBrowser && !options.noUI && sequencer.getSteps().length < 2) options.offset = -1; - if (options.step.inBrowser && !options.noUI) var ui = require('./Ui.js')(options.step, UI); + let ui; - var output; + if (options.step.inBrowser && !options.noUI) ui = require('./Ui.js')(options.step, UI); + + let output; // This function is called on every draw. function draw(input, callback, progressObj) { @@ -19,15 +21,15 @@ module.exports = function Dynamic(options, UI, util) { progressObj.stop(true); progressObj.overrideFlag = true; - var step = this; + const step = this; - var parseCornerCoordinateInputs = require('../../util/ParseInputCoordinates'); + const parseCornerCoordinateInputs = require('../../util/ParseInputCoordinates'); // save the pixels of the base image - var baseStepImage = this.getStep(options.offset).image; - var baseStepOutput = this.getOutput(options.offset); + const baseStepImage = this.getStep(options.offset).image; + const baseStepOutput = this.getOutput(options.offset); - var getPixels = require('get-pixels'); + const getPixels = require('get-pixels'); getPixels(input.src, function(err, pixels) { // parse the inputs @@ -47,16 +49,16 @@ module.exports = function Dynamic(options, UI, util) { function changePixel(r1, g1, b1, a1, x, y) { - var firstImagePixels = [r1, g1, b1, a1]; + const firstImagePixels = [r1, g1, b1, a1]; // overlay - var p = options.secondImagePixels; + const p = options.secondImagePixels; if (x >= options.x && x - options.x < p.shape[0] && y >= options.y && y - options.y < p.shape[1]){ - var secondImagePixels = [ + const secondImagePixels = [ p.get(x - options.x, y - options.y, 0), p.get(x - options.x, y - options.y, 1), p.get(x - options.x, y - options.y, 2),