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.
* 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
- Loading branch information
Showing
7 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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 | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"name": "Resize", | ||
"description": "Resize image by given percentage value", | ||
"inputs": { | ||
"resize": { | ||
"type": "string", | ||
"desc": "Percentage value of the resize", | ||
"default": "125%" | ||
} | ||
} | ||
} |
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