0.2.0 • Published 5 years ago

ndarray-resize v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

ndarray-resize

build status coverage status greenkeeper

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

ParamTypeDefaultDescription
originalndarrayAn ndarray of the image to warp
optionsObjectConfiguration options
options.algorithmstring"bilinear"The algorithm to use for resizing, either 'nearestNeighbour', 'bilinear', 'cosine', 'bicubic', 'cattmullRom', 'hermite' or 'bezier'
options.targetHeightnumberThe target height in pixels
options.targetWidthnumberThe target width in pixels
options.tensionnumberAllows you to set the tension for hermite interpolation
options.biasnumberAllows you to set the bias for hermite interpolation

License

MIT

0.2.0

5 years ago

0.1.0

5 years ago