image-processor

0.1.1 • Public • Published

Image Processor using Node Streams


This library processes images by passing a readabale stream (or file paths) and writes it into a writable stream. It uses jpegtran for jpg methods, optipng and gifsicle-stream for optimizing png & gif files, respectively. The current fallback for PNG and GIF operations uses gm.


Installation & Usage

npm install --save image-processor
var ImageProcessor = require('image-processor'),
    rs = fs.createReadStream('photos/batman.gif'),
    photo = 'photos/photo2.jpg';
 
// Accept a readable stream
var imageProcessor = new ImageProcessor(rs);
 
// Accept a file path
var imageProcessorFilePath = new ImageProcessor(photo);
 
//Configure options
//See API below to properly configure options per method
var opts = { interlaced: true, arithmetic: true };
 
imageProcessor.optimize(opts, function (err, data) {
  if (err) {
    console.error(err);
  }
 
  res.send(data);
});

API

  • imageProcessor.crop(w, h, x, y, callback);

      imageStream.crop(800, 800, 0, 0, function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.rotate(deg, callback);

      imageStream.rotate(270, function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.scale(w, h, callback);

      imageStream.scale(1, 8, function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.resize(w, h, callback);

      imageStream.resize(800, 800, function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.minify(callback);

      imageStream.minify(function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.optimize(opts, callback);

      var opts = {
        progressive: true,
        arithmetic: true
      };
      imageStream.optimize(opts, function (err, data) {
        if (err) { console.log(err); }
     
        console.log(data);
      });
  • imageProcessor.getImgDimensions(callback);

      imageStream.getImgDimensions(function(err, dimensions) {
        if (err) { console.log(err); }
     
        console.log('width: ' + dimensions.width + ' x ' + 'height: ' + dimensions.height);
      });

Supported file types

  • JPG / JPEG
  • PNG
  • GIF
  • TIFF

Package Sidebar

Install

npm i image-processor

Weekly Downloads

1

Version

0.1.1

License

ISC

Last publish

Collaborators

  • dexterbrylle