mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 12:19:58 +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:
33
package-lock.json
generated
33
package-lock.json
generated
@@ -482,6 +482,11 @@
|
|||||||
"integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=",
|
"integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"bluebird": {
|
||||||
|
"version": "3.5.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.2.tgz",
|
||||||
|
"integrity": "sha512-dhHTWMI7kMx5whMQntl7Vr9C6BvV10lFXDAasnqnrMYhXVCzzk6IO9Fo2L75jXHT07WrOngL1WDXOp+yYS91Yg=="
|
||||||
|
},
|
||||||
"bn.js": {
|
"bn.js": {
|
||||||
"version": "4.11.8",
|
"version": "4.11.8",
|
||||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
||||||
@@ -4314,6 +4319,24 @@
|
|||||||
"resolved": "https://registry.npmjs.org/image-sequencer-invert/-/image-sequencer-invert-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/image-sequencer-invert/-/image-sequencer-invert-1.0.0.tgz",
|
||||||
"integrity": "sha512-LL9jwCnSbUy676q9ULJ6M04mp1TVOxpjlckMGN2SyFOgPE4SGL2/IRcO33BDwafmFiupqDdgs7gUHEbsFcCqgQ=="
|
"integrity": "sha512-LL9jwCnSbUy676q9ULJ6M04mp1TVOxpjlckMGN2SyFOgPE4SGL2/IRcO33BDwafmFiupqDdgs7gUHEbsFcCqgQ=="
|
||||||
},
|
},
|
||||||
|
"imagejs": {
|
||||||
|
"version": "0.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/imagejs/-/imagejs-0.0.9.tgz",
|
||||||
|
"integrity": "sha1-JoBkWQD211+/D2e7wAY+aIiufr4=",
|
||||||
|
"requires": {
|
||||||
|
"bluebird": "*",
|
||||||
|
"jpeg-js": "0.1.1",
|
||||||
|
"node-png": "0.4.3",
|
||||||
|
"underscore": "1.4.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jpeg-js": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.1.1.tgz",
|
||||||
|
"integrity": "sha1-Kl/xljb+J+O2Za2UI0dctraYaY0="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"imgareaselect": {
|
"imgareaselect": {
|
||||||
"version": "git://github.com/jywarren/imgareaselect.git#db8ae869ca0fcb289252678cebd17d6f40711f61",
|
"version": "git://github.com/jywarren/imgareaselect.git#db8ae869ca0fcb289252678cebd17d6f40711f61",
|
||||||
"from": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2"
|
"from": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2"
|
||||||
@@ -5496,6 +5519,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/node-bitmap/-/node-bitmap-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/node-bitmap/-/node-bitmap-0.0.1.tgz",
|
||||||
"integrity": "sha1-GA6scAPgxwdhjvMTaPYvhLKmkJE="
|
"integrity": "sha1-GA6scAPgxwdhjvMTaPYvhLKmkJE="
|
||||||
},
|
},
|
||||||
|
"node-png": {
|
||||||
|
"version": "0.4.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-png/-/node-png-0.4.3.tgz",
|
||||||
|
"integrity": "sha1-RQIjeWuC08yg/+Sl1cf6l0hZdOc="
|
||||||
|
},
|
||||||
"nopt": {
|
"nopt": {
|
||||||
"version": "3.0.6",
|
"version": "3.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/nopt/-/nopt-3.0.6.tgz",
|
||||||
@@ -8100,6 +8128,11 @@
|
|||||||
"xtend": "^4.0.1"
|
"xtend": "^4.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"underscore": {
|
||||||
|
"version": "1.4.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.4.4.tgz",
|
||||||
|
"integrity": "sha1-YaajIBBiKvoHljvzJSA88SI51gQ="
|
||||||
|
},
|
||||||
"underscore.string": {
|
"underscore.string": {
|
||||||
"version": "3.3.5",
|
"version": "3.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.5.tgz",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"font-awesome": "~4.5.0",
|
"font-awesome": "~4.5.0",
|
||||||
"get-pixels": "~3.3.0",
|
"get-pixels": "~3.3.0",
|
||||||
"image-sequencer-invert": "^1.0.0",
|
"image-sequencer-invert": "^1.0.0",
|
||||||
|
"imagejs": "0.0.9",
|
||||||
"imgareaselect": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2",
|
"imgareaselect": "git://github.com/jywarren/imgareaselect.git#v1.0.0-rc.2",
|
||||||
"jquery": "^3.3.1",
|
"jquery": "^3.3.1",
|
||||||
"jsqr": "^0.2.2",
|
"jsqr": "^0.2.2",
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ module.exports = {
|
|||||||
'histogram': require('./modules/Histogram'),
|
'histogram': require('./modules/Histogram'),
|
||||||
'gamma-correction': require('./modules/GammaCorrection'),
|
'gamma-correction': require('./modules/GammaCorrection'),
|
||||||
'convolution': require('./modules/Convolution'),
|
'convolution': require('./modules/Convolution'),
|
||||||
|
'resize': require('./modules/Resize')
|
||||||
}
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/modules/Resize/index.js
Normal file
4
src/modules/Resize/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = [
|
||||||
|
require('./Module'),
|
||||||
|
require('./info.json')
|
||||||
|
]
|
||||||
11
src/modules/Resize/info.json
Normal file
11
src/modules/Resize/info.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "Resize",
|
||||||
|
"description": "Resize image by given percentage value",
|
||||||
|
"inputs": {
|
||||||
|
"resize": {
|
||||||
|
"type": "string",
|
||||||
|
"desc": "Percentage value of the resize",
|
||||||
|
"default": "125%"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -189,16 +189,15 @@ test('toCliString() returns the CLI command for the sequence', function(t) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('blend returns different output depending on the set offset', function(t) {
|
test('blend returns different output depending on the set offset', function(t) {
|
||||||
var blend_2;
|
sequencer.addSteps('test', 'invert', {});
|
||||||
sequencer.addSteps('test', 'invert', {});
|
sequencer.addSteps('test', 'invert', {});
|
||||||
sequencer.addSteps('test', 'invert', {});
|
sequencer.addSteps('test', 'blend', {});
|
||||||
sequencer.addSteps('test', 'blend', {});
|
// because we've added blend before, so instead of -3 we set it to -4
|
||||||
// because we've added blend before, so instead of -3 we set it to -4
|
sequencer.addSteps('test', 'blend', {'offset': -4});
|
||||||
sequencer.addSteps('test', 'blend', {'offset': -4});
|
sequencer.run({ mode: 'test' }, function(out) {
|
||||||
sequencer.run({ mode: 'test' }, function(out) {
|
t.notStrictEqual(out, sequencer.images.test.steps[sequencer.images.test.steps.length - 2].output.src, 'different offsets give different output');
|
||||||
t.notStrictEqual(out, sequencer.images.test.steps[sequencer.images.test.steps.length - 2].output.src, 'different offsets give different output');
|
t.end();
|
||||||
t.end();
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('replaceImage returns false in NodeJS', function(t) {
|
test('replaceImage returns false in NodeJS', function(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user