mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 20:00:05 +01:00
revived Crop Module
This commit is contained in:
@@ -3,7 +3,7 @@ function AddStep(ref, image, name, o) {
|
|||||||
function addStep(image, name, o_) {
|
function addStep(image, name, o_) {
|
||||||
ref.log('\x1b[36m%s\x1b[0m','adding step \"' + name + '\" to \"' + image + '\".');
|
ref.log('\x1b[36m%s\x1b[0m','adding step \"' + name + '\" to \"' + image + '\".');
|
||||||
|
|
||||||
o = {};
|
o = ref.copy(o_);
|
||||||
o.id = ref.options.sequencerCounter++; //Gives a Unique ID to each step
|
o.id = ref.options.sequencerCounter++; //Gives a Unique ID to each step
|
||||||
o.name = o_.name || name;
|
o.name = o_.name || name;
|
||||||
o.selector = o_.selector || 'ismod-' + name;
|
o.selector = o_.selector || 'ismod-' + name;
|
||||||
|
|||||||
@@ -6,5 +6,6 @@ module.exports = {
|
|||||||
'green-channel': require('./modules/GreenChannel'),
|
'green-channel': require('./modules/GreenChannel'),
|
||||||
'ndvi-red': require('./modules/NdviRed'),
|
'ndvi-red': require('./modules/NdviRed'),
|
||||||
'do-nothing-pix': require('./modules/DoNothingPix'),
|
'do-nothing-pix': require('./modules/DoNothingPix'),
|
||||||
'invert': require('./modules/Invert')
|
'invert': require('./modules/Invert'),
|
||||||
|
'crop': require('./modules/Crop')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,18 +13,20 @@
|
|||||||
* y = options.y
|
* y = options.y
|
||||||
* y = options.y + options.h
|
* y = options.y + options.h
|
||||||
*/
|
*/
|
||||||
module.exports = function Crop(options){
|
module.exports = function Crop(options) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.title = "Crop Image";
|
options.title = "Do Nothing";
|
||||||
options.format = options.format || "png";
|
this_ = this;
|
||||||
|
var output
|
||||||
|
var getPixels = require("get-pixels"),
|
||||||
|
savePixels = require("save-pixels"),
|
||||||
|
base64 = require('base64-stream');
|
||||||
|
|
||||||
function draw(image) {
|
function draw(input,callback) {
|
||||||
var getPixels = require("get-pixels"),
|
|
||||||
savePixels = require("save-pixels"),
|
|
||||||
base64 = require('base64-stream');
|
|
||||||
|
|
||||||
getPixels(image.src,function(err,pixels){
|
const this_ = this;
|
||||||
|
|
||||||
|
getPixels(input.src,function(err,pixels){
|
||||||
var newdata = [];
|
var newdata = [];
|
||||||
var ox = options.x || 0;
|
var ox = options.x || 0;
|
||||||
var oy = options.y || 0;
|
var oy = options.y || 0;
|
||||||
@@ -39,23 +41,23 @@
|
|||||||
pixels.shape = [w,h,4];
|
pixels.shape = [w,h,4];
|
||||||
pixels.stride[1] = 4*w;
|
pixels.stride[1] = 4*w;
|
||||||
|
|
||||||
var buffer = base64.encode();
|
options.format = "jpeg";
|
||||||
savePixels(pixels, options.format)
|
|
||||||
.on('end', function() {
|
|
||||||
|
|
||||||
var img = new Image();
|
|
||||||
|
|
||||||
img.src = 'data:image/' + options.format + ';base64,' + buffer.read().toString();
|
|
||||||
|
|
||||||
if (options.output) options.output(img);
|
|
||||||
|
|
||||||
}).pipe(buffer);
|
|
||||||
|
|
||||||
|
w = base64.encode();
|
||||||
|
var r = savePixels(pixels, options.format);
|
||||||
|
r.pipe(w).on('finish',function(){
|
||||||
|
data = w.read().toString();
|
||||||
|
datauri = 'data:image/' + options.format + ';base64,' + data;
|
||||||
|
this_.output = {src:datauri,format:options.format};
|
||||||
|
callback();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
options: options,
|
options: options,
|
||||||
draw: draw
|
draw: draw,
|
||||||
|
output: output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user