1.0.0 • Published 7 years ago

node-image-resizer v1.0.0

Weekly downloads
24
License
MIT
Repository
github
Last release
7 years ago

node-image-resizer

Get some image and generate its smaller copies. You can also control the quality, brightness and contrast. Asynchronously.

Installation

npm i -D node-image-resizer

Usage

import resizer from 'node-image-resizer';

(async () => {
  await resizer('./image.jpg', setup);
})();

Returns array of file names (with path) for generated thumbnails.

Setup

You can create as many thumbnails from your image as you wish.

All definitions (for each thumbnail separately) are grouped in one object with following structure:

const setup = { 
  all: {},                 // general settings to apply on each thumbnail
  versions: [{}, {}, {}]   // unique settings for each thumbnail; will overwrite general setting
};

for example:

const setup = { 
  all: {
    path: './thumbnails/',
    quality: 80
  },
  versions: [{
    prefix: 'big_',
    width: 1024,
    height: 768
  }, {
    prefix: 'medium_',
    width: 512,
    height: 256
  }, {
    quality: 100,
    prefix: 'small_',
    width: 128,
    height: 64
  }]
};

// create thumbnails
const thumbs = await resizer('./image.jpg', setup);

Settings from versions overwrite values from all.

Options

All options are optional.

nametypedefaultdescription
pathstringDestination path for generated image.
prefixstringUsed to create file name based on source file name. Will overwrite a file with the same name if exists.
suffixstringUsed to create file name based on source file name. Will overwrite a file with the same name if exists.
widthnumbersource image widthWidth of the new image (in px).
heightnumbersource image heightHeight of the new image (in px).
contrastnumberAdjust the contrast by a value -1 to +1.
brightnessnumberAdjust the brightness by a value -1 to +1.
qualitynumberSet the quality of saved JPEG by a value 0 - 100.
normalizebooleanfalseNormalize the channels in the new image.

License

MIT