Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Sketch Module #1450

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions src/Modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
'resize': require('./modules/Resize'),
'rotate': require('./modules/Rotate'),
'saturation': require('./modules/Saturation'),
'sketch': require('./modules/Sketch'),
'text-overlay': require('./modules/TextOverlay'),
'threshold': require('./modules/Threshold'),
'tint': require('./modules/Tint'),
Expand Down
80 changes: 80 additions & 0 deletions src/modules/Sketch/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module.exports = function Sketch(options, UI) {
// var defaults = require('../../util/getDefaults.js')(require('./info.json'));
var output;


function draw(input, callback, progressObj) {
progressObj.stop(true);
progressObj.overrideFlag = true;

var defaults = require('../../util/getDefaults.js')(require('./info.json'));

var step = this;
var priorStep = this.getStep(-1);
options.channel = options.channel || defaults.channel ;
options.thickness = options.thickness || defaults.thickness ;

var Sketcher = require('./Sketch.js');
var getPixels = require('get-pixels');
getPixels(priorStep.output.src, function(err, pixels) {
// ImagePixels = pixels;
var $ = require('jquery'); // To make Blob-analysis work in Node
var img = $(priorStep.imgElement);
if(Object.keys(img).length === 0){
img = $(priorStep.options.step.imgElement);
}

var canvas = document.createElement('canvas');
canvas.width = pixels.shape[0];
canvas.height = pixels.shape[1];

var context = canvas.getContext('2d');



context.drawImage(img[0], 0, 0);


var sketcher = new Sketcher.Sketcher(canvas.width, canvas.height,options);
sketcher.transformCanvas(canvas,options).whenReady(function () {

function extraManipulation(pixels){
context = canvas.getContext('2d');

var myImageData = context.getImageData(0, 0, canvas.width, canvas.height);
pixels.data = myImageData.data;

return pixels;
}

function output(image, datauri, mimetype, wasmSuccess) {
step.output = { src: datauri, format: mimetype, wasmSuccess, useWasm: options.useWasm };
}

return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
// return this.pixela;
});

});







}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};
Loading