mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-11 19:00:00 +01:00
* 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>
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
/*
|
|
* 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
|
|
};
|
|
};
|