mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 12:19:58 +01:00
Add support for transparent image in overlay module (#1606)
* add support for transparent image overlay * replaced var for const/let Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
module.exports = function Dynamic(options, UI, util) {
|
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.x = options.x || defaults.x;
|
||||||
options.y = options.y || defaults.y;
|
options.y = options.y || defaults.y;
|
||||||
|
|
||||||
if(options.step.inBrowser && !options.noUI && sequencer.getSteps().length < 2)
|
if(options.step.inBrowser && !options.noUI && sequencer.getSteps().length < 2)
|
||||||
options.offset = -1;
|
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.
|
// This function is called on every draw.
|
||||||
function draw(input, callback, progressObj) {
|
function draw(input, callback, progressObj) {
|
||||||
@@ -19,15 +21,15 @@ module.exports = function Dynamic(options, UI, util) {
|
|||||||
progressObj.stop(true);
|
progressObj.stop(true);
|
||||||
progressObj.overrideFlag = 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
|
// save the pixels of the base image
|
||||||
var baseStepImage = this.getStep(options.offset).image;
|
const baseStepImage = this.getStep(options.offset).image;
|
||||||
var baseStepOutput = this.getOutput(options.offset);
|
const baseStepOutput = this.getOutput(options.offset);
|
||||||
|
|
||||||
var getPixels = require('get-pixels');
|
const getPixels = require('get-pixels');
|
||||||
|
|
||||||
getPixels(input.src, function(err, pixels) {
|
getPixels(input.src, function(err, pixels) {
|
||||||
// parse the inputs
|
// parse the inputs
|
||||||
@@ -47,20 +49,29 @@ module.exports = function Dynamic(options, UI, util) {
|
|||||||
|
|
||||||
function changePixel(r1, g1, b1, a1, x, y) {
|
function changePixel(r1, g1, b1, a1, x, y) {
|
||||||
|
|
||||||
|
const firstImagePixels = [r1, g1, b1, a1];
|
||||||
|
|
||||||
// overlay
|
// overlay
|
||||||
var p = options.secondImagePixels;
|
const p = options.secondImagePixels;
|
||||||
if (x >= options.x
|
if (x >= options.x
|
||||||
&& x - options.x < p.shape[0]
|
&& x - options.x < p.shape[0]
|
||||||
&& y >= options.y
|
&& y >= options.y
|
||||||
&& y - options.y < p.shape[1])
|
&& y - options.y < p.shape[1]){
|
||||||
return [
|
|
||||||
|
const secondImagePixels = [
|
||||||
p.get(x - options.x, y - options.y, 0),
|
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, 1),
|
||||||
p.get(x - options.x, y - options.y, 2),
|
p.get(x - options.x, y - options.y, 2),
|
||||||
p.get(x - options.x, y - options.y, 3)
|
p.get(x - options.x, y - options.y, 3)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if(secondImagePixels[3] === 0)
|
||||||
|
return firstImagePixels;
|
||||||
else
|
else
|
||||||
return [r1, g1, b1, a1];
|
return secondImagePixels;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return firstImagePixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
function output(image, datauri, mimetype, wasmSuccess) {
|
function output(image, datauri, mimetype, wasmSuccess) {
|
||||||
|
|||||||
Reference in New Issue
Block a user