0.2.0 • Published 5 years ago
ndarray-resize v0.2.0
ndarray-resize
This module allows you to resize an image in pure javascript without any external native dependencies. It'll work in both node and the browser, though you might have to transpile with babel depending on the javascript syntax your target audience supports.
Installation
npm install ndarray-resize
Example
So for example, to resize an image to a 100 x 100 pixels:
const util = require('util');
const getPixels = util.promisify(require('get-pixels'));
const save = require('save-pixels');
const fs = require('fs');
const streamToPromise = require('stream-to-promise');
const resize = require('ndarray-resize');
const algorithm = 'bicubic';
const targetWidth = 100;
const targetHeight = 100;
getPixels('input.png')
.then(image => {
const resized = resize(image, { targetWidth, targetHeight, algorithm });
return streamToPromise(savePixels(resized, 'png'));
})
.then(resizedImage => {
fs.writeFileSync('resized.png', resizedImage);
});
API
resize(original, options) ⇒ ndarray
Resizes an image according to the provided target width and height
Kind: global function Returns: ndarray - The resized image
Param | Type | Default | Description |
---|---|---|---|
original | ndarray | An ndarray of the image to warp | |
options | Object | Configuration options | |
options.algorithm | string | "bilinear" | The algorithm to use for resizing, either 'nearestNeighbour', 'bilinear', 'cosine', 'bicubic', 'cattmullRom', 'hermite' or 'bezier' |
options.targetHeight | number | The target height in pixels | |
options.targetWidth | number | The target width in pixels | |
options.tension | number | Allows you to set the tension for hermite interpolation | |
options.bias | number | Allows you to set the bias for hermite interpolation |