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
- Form upload
imager.upload(req, function(err, files, cdnUri){
}, 'projects')
- 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){
}, 'projects')
Upload multiple files from disk:
var files = ['file1.jpg', 'file2.jpg']
imager.upload(files, function(err, files, cdnUri){
}, 'projects')
- Upload files from remote url
imager.uploadRemoteImage('https://www.google.co.in/images/srpr/logo3w.png', function(err, files, cdnUri){
}, 'projects')
Removing file(s)
- Remove a single file
imager.remove('1330838831049.png', function (err) {
}, 'projects')
- Remove multiple files
var files = ['1330838831049.png', '1330838831049.png']
imager.remove(files, function (err) {
}, 'projects')
To-do's
- Support amazon storage
- Support filesystem storage
Remove using of eval
Add functionality to remove files- Write tests