mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-18 06:10:12 +01:00
Added aspect ratio module (#1454)
* Base file * Added aspect ratio module * Compatiable with Experimental GIF Manipulation * some refactoring * Changed the name from aspect-ratio to Constrained Crop * cleanup * Changes requested * Added test module Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
This commit is contained in:
committed by
Jeffrey Warren
parent
5ae545904d
commit
2736b481a4
@@ -13,6 +13,7 @@ module.exports = {
|
|||||||
'colorbar': require('./modules/Colorbar'),
|
'colorbar': require('./modules/Colorbar'),
|
||||||
'color-temperature': require('./modules/ColorTemperature'),
|
'color-temperature': require('./modules/ColorTemperature'),
|
||||||
'colormap': require('./modules/Colormap'),
|
'colormap': require('./modules/Colormap'),
|
||||||
|
'constrained-crop': require('./modules/ConstrainedCrop'),
|
||||||
'contrast': require('./modules/Contrast'),
|
'contrast': require('./modules/Contrast'),
|
||||||
'convolution': require('./modules/Convolution'),
|
'convolution': require('./modules/Convolution'),
|
||||||
'crop': require('./modules/Crop'),
|
'crop': require('./modules/Crop'),
|
||||||
|
|||||||
56
src/modules/ConstrainedCrop/Module.js
Normal file
56
src/modules/ConstrainedCrop/Module.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Crops an Image on the basis of the ratio provided
|
||||||
|
*/
|
||||||
|
module.exports = function ConstrainedCrop(options, UI) {
|
||||||
|
|
||||||
|
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
|
||||||
|
var output;
|
||||||
|
|
||||||
|
function draw(input, callback) {
|
||||||
|
|
||||||
|
var step = this,
|
||||||
|
startingX = Number(options.startingX || defaults.startingX),
|
||||||
|
startingY = Number(options.startingY || defaults.startingY),
|
||||||
|
aspectRatio = (options.aspectRatio || defaults.aspectRatio).split(':'),
|
||||||
|
widthRatio = Number(aspectRatio[0]),
|
||||||
|
heightRatio = Number(aspectRatio[1]);
|
||||||
|
|
||||||
|
function extraManipulation(pixels) {
|
||||||
|
var width = pixels.shape[0],
|
||||||
|
height = pixels.shape[1];
|
||||||
|
var endX, endY;
|
||||||
|
if(((width - startingX) / widthRatio) * heightRatio <= (height - startingY)) {
|
||||||
|
endX = width;
|
||||||
|
endY = (((width - startingX) / widthRatio) * heightRatio) + startingY;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
endX = (((height - startingY) / heightRatio) * widthRatio) + startingX;
|
||||||
|
endY = height;
|
||||||
|
}
|
||||||
|
const newPixels = require('../Crop/Crop')(pixels, {'x': startingX, 'y': startingY, 'w': endX - startingX, 'h': endY - startingY}, function() {
|
||||||
|
});
|
||||||
|
return newPixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function output(image, datauri, mimetype, wasmSuccess) {
|
||||||
|
step.output = { src: datauri, format: mimetype, wasmSuccess, useWasm: options.useWasm };
|
||||||
|
}
|
||||||
|
return require('../_nomodule/PixelManipulation')(input, {
|
||||||
|
output: output,
|
||||||
|
ui: options.step.ui,
|
||||||
|
extraManipulation: extraManipulation,
|
||||||
|
format: input.format,
|
||||||
|
image: options.image,
|
||||||
|
inBrowser: options.inBrowser,
|
||||||
|
callback: callback,
|
||||||
|
useWasm:options.useWasm
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
options: options,
|
||||||
|
draw: draw,
|
||||||
|
output: output,
|
||||||
|
UI: UI
|
||||||
|
};
|
||||||
|
};
|
||||||
4
src/modules/ConstrainedCrop/index.js
Normal file
4
src/modules/ConstrainedCrop/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = [
|
||||||
|
require('./Module'),
|
||||||
|
require('./info.json')
|
||||||
|
];
|
||||||
23
src/modules/ConstrainedCrop/info.json
Normal file
23
src/modules/ConstrainedCrop/info.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "constrained-crop",
|
||||||
|
"description": "Crops an image in a particular aspect-ratio",
|
||||||
|
"inputs": {
|
||||||
|
"startingX": {
|
||||||
|
"type": "integer",
|
||||||
|
"desc": "X-position (measured from left) from where cropping starts",
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"startingY": {
|
||||||
|
"type": "integer",
|
||||||
|
"desc": "Y-position (measured from top) from where cropping starts",
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"aspectRatio":{
|
||||||
|
"type": "string",
|
||||||
|
"desc": "Enter aspect ratio in following format width:height",
|
||||||
|
"default": "1:1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"docs-link":""
|
||||||
|
}
|
||||||
|
|
||||||
10
test/core/modules/constrained-crop.js
Normal file
10
test/core/modules/constrained-crop.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user