mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 20:30:01 +01:00
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
/*
|
|
* Resize the image by given percentage value
|
|
*/
|
|
module.exports = function Resize(options, UI) {
|
|
|
|
var output;
|
|
|
|
function draw(input, callback, progressObj) {
|
|
|
|
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
|
|
options.resize = options.resize || defaults.resize;
|
|
|
|
progressObj.stop(true);
|
|
progressObj.overrideFlag = true;
|
|
|
|
var step = this;
|
|
|
|
var imagejs = require('imagejs');
|
|
|
|
function changePixel(r, g, b, a) {
|
|
return [r, g, b, a];
|
|
}
|
|
|
|
function extraManipulation(pixels) {
|
|
// value above 100% scales up, and below 100% scales down
|
|
var resize_value = parseInt(options.resize.slice(0, -1));
|
|
|
|
var new_width,
|
|
new_height;
|
|
|
|
new_width = Math.round(pixels.shape[0] * (resize_value / 100));
|
|
new_height = Math.round(pixels.shape[1] * (resize_value / 100));
|
|
|
|
var bitmap = new imagejs.Bitmap({width: pixels.shape[0], height: pixels.shape[1]});
|
|
bitmap._data.data = pixels.data;
|
|
|
|
|
|
var resized = bitmap.resize({
|
|
width: new_width, height: new_height,
|
|
algorithm: 'bicubicInterpolation'
|
|
});
|
|
|
|
pixels.data = resized._data.data;
|
|
pixels.shape = [new_width,new_height,4];
|
|
pixels.stride[1] = 4 * new_width;
|
|
|
|
return pixels;
|
|
}
|
|
|
|
function output(image, datauri, mimetype) {
|
|
// This output is accesible by Image Sequencer
|
|
step.output = { src: datauri, format: mimetype };
|
|
}
|
|
|
|
return require('../_nomodule/PixelManipulation.js')(input, {
|
|
output: output,
|
|
changePixel: changePixel,
|
|
extraManipulation: extraManipulation,
|
|
format: input.format,
|
|
image: options.image,
|
|
inBrowser: options.inBrowser,
|
|
callback: callback
|
|
});
|
|
}
|
|
|
|
return {
|
|
options: options,
|
|
draw: draw,
|
|
output: output,
|
|
UI: UI
|
|
};
|
|
};
|