mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 04:10:04 +01:00
Add resize module (#451)
* added resize module - without test * Added resize test, deleted unused value in blend test (which I've added before) * Fixed test * Fixed test * added modules file * added imagejs to package * removed test - not able to check width and height of the element * Changed resize calculations
This commit is contained in:
71
src/modules/Resize/Module.js
Normal file
71
src/modules/Resize/Module.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Resize the image by given percentage value
|
||||
*/
|
||||
module.exports = function Resize(options, UI) {
|
||||
|
||||
var output;
|
||||
|
||||
function draw(input, callback, progressObj) {
|
||||
|
||||
options.resize = options.resize || "125%";
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user