JSPM

  • Created
  • Published
  • Downloads 49
  • Score
    100M100P100Q58692F

Easy way to resize, crop and upload images to Rackspace cloudfiles

Package Exports

  • imager

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (imager) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Imager

A Node.js module to easily resize, crop and upload images to Rackspace cloudfiles. Possible to add different versions of the same file in cropped or resized variant.

Installation

$ npm install imager

Usage

You need to create imager configuration file with image variants and your storages

Checkout the example config file imager-example.json in the repo

var Imager = require('imager');
var imager = new Imager({storage : "rs", config_file: "path/to/imager_config.json"})

Uploading file(s)

The callback recieves an err object, a files array (containing the names of the files which were uploaded) and the cdnUri.

So if you have a variant, say thumb, then you can access the image by cdnUri+'/'+'thumb_'+files[0]. This would be the complete url of the image

  1. Form upload
imager.upload(req, function(err, files, cdnUri){
    // do your stuff
}, 'projects')
  1. Upload files from disk

You can upload a single file or multiple files by providing the paths to all the files in an array

Upload Single file from disk:

imager.upload('path/to/file.jpg', function(err, files, cdnUri){
    // do your stuff
}, 'projects')

Upload multiple files from disk:

var files = ['file1.jpg', 'file2.jpg']
imager.upload(files, function(err, files, cdnUri){
    // do your stuff
}, 'projects')
  1. Upload files from remote url
imager.uploadRemoteImage('https://www.google.co.in/images/srpr/logo3w.png', function(err, files, cdnUri){
    // do your stuff
}, 'projects')

Removing file(s)

  1. Remove a single file
imager.remove('1330838831049.png', function (err) {
    // do your stuff
}, 'projects')
  1. Remove multiple files
var files = ['1330838831049.png', '1330838831049.png']
imager.remove(files, function (err) {
    // do your stuff
}, 'projects')

To-do's

  • Support amazon storage
  • Support filesystem storage
  • Remove using of eval
  • Add functionality to remove files
  • Write tests