forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: h <f> Co-authored-by: Harsh Khandeparkar <34770591+HarshKhandeparkar@users.noreply.github.com> Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
- Loading branch information
1 parent
1713751
commit d33afe0
Showing
2 changed files
with
45 additions
and
41 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,44 @@ | ||
const imagejs = require('imagejs'), | ||
pixelSetter = require('../../util/pixelSetter'), | ||
ndarray = require('ndarray'); | ||
module.exports = function Resize(pixels, options) { | ||
const resize_value = parseInt(options.resize.slice(0, -1)); | ||
|
||
if (resize_value == 100) return pixels; | ||
|
||
const new_width = Math.round(pixels.shape[0] * (resize_value / 100)), | ||
new_height = Math.round(pixels.shape[1] * (resize_value / 100)); | ||
|
||
const bitmap = new imagejs.Bitmap({ | ||
width: pixels.shape[0], | ||
height: pixels.shape[1] | ||
}); | ||
|
||
for (let x = 0; x < pixels.shape[0]; x++) { | ||
for (let y = 0; y < pixels.shape[1]; y++) { | ||
let r = pixels.get(x, y, 0), | ||
g = pixels.get(x, y, 1), | ||
b = pixels.get(x, y, 2), | ||
a = pixels.get(x, y, 3); | ||
|
||
bitmap.setPixel(x, y, r, g, b, a); | ||
} | ||
} | ||
|
||
const resized = bitmap.resize({ | ||
width: new_width, | ||
height: new_height, | ||
algorithm: 'bicubicInterpolation' | ||
}); | ||
|
||
const newPix = new ndarray([], [new_width, new_height, 4]); | ||
|
||
for (let x = 0; x < new_width; x++) { | ||
for (let y = 0; y < new_height; y++) { | ||
const { r, g, b, a } = resized.getPixel(x, y); | ||
pixelSetter(x, y, [r, g, b, a], newPix); | ||
} | ||
} | ||
|
||
return newPix; | ||
}; |