forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <[email protected]> Co-authored-by: Jeffrey Warren <[email protected]>
- Loading branch information
1 parent
5ae5459
commit 2736b48
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = [ | ||
require('./Module'), | ||
require('./info.json') | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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":"" | ||
} | ||
|
Oops, something went wrong.