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 @@ -40,6 +40,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 step = this;
var priorStep = this.getStep(-1);
// options.Segments = options.Segments || defaults.Segments ;
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);
sketcher.progressUpdate(function (proportion, message) {
console.log((Math.round(proportion * 1000) / 10) + '% done - ' + message);
// document.title = (Math.round(proportion*1000)/10) + "% done - " + message;
});
sketcher.transformCanvas(canvas).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