1.0.3 • Published 9 years ago

jpeg-turbo-scaler v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

Node.js JPEG turbo scaler module

Native C++ Node.js module which uses libjpeg-turbo for extremely fast JPEG compression and decompression.

Installation

The module have been tested to build correctly only on OS X and requires libjpeg-turbo to be installed manually via Homebrew. It should be pretty easy to build it on any system, the only dependency is libjpeg-turbo library which you can easily install using your favorite package manager and simply add include and lib directories to bindings.gyp file.

Installation sequence:

  • Install libjpeg-turbo
brew install jpeg-turbo
  • Install the module using npm
npm install jpeg-turbo-scaler

Usage

function decompress(path, targetWidth, targetHeight, callback)

Reads a JPEG file referenced by path from local file system and resizes it to fit into targetWidthxtargetHeight box keeping original aspect ratio.

path: a string containing JPEG image file path (absolute or relative).

targetWidth and targetHeight: desired dimensions of decompressed image.

callback: function(bitmap, width, height) where bitmap is a Buffer with RGBA pixels data.

function scale(path, targetWidth, targetHeight, callback)

Reads a JPEG file referenced by path from local file system, resizes it to fit into targetWidthxtargetHeight box keeping original aspect ratio, and compresses the result to JPEG.

path: a string containing JPEG image file path (absolute or relative).

targetWidth and targetHeight: desired dimensions of decompressed image.

callback: function(jpeg, width, height) where bitmap is a JPEG file data.

Example

var jpeg = require('jpeg-turbo-scaler');
jpeg.decompress('image.jpg', 300, 300, function(bitmap, width, height) {
  console.log('Got ' + bitmap.length + ' bytes RGBA bitmap');
});

jpeg.scale('image.jpg', 300, 300, function(jpeg, width, height) {
  console.log('Got ' + jpeg.length + ' scaled JPEG file');
  require('fs').writeFileSync('output.jpg', jpeg);
});
1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago