wip: This is work in progress. Converting to use generators and graphicsmagick-stream library. The uploading is handled by pkgcloud. The master branch and 1.0.0-alpha1 tag works only with s3.
Imager
A node module to resize, crop and upload images (with different variants and presets) to the cloud.
Dependencies
- node >= 0.11.12 with
--harmony
flag - You need to install libgraphicsmagicks.
Using osx
$ brew install graphicsmagick --build-from-source
Using ubuntu
$ sudo apt-get install libgraphicsmagick1-dev
Installation
$ npm install imager
Config
Use a config file. For example imager-config.js
variants
exportsvariants = item: // variant thumb: // preset options: // preset options pool: 5 scale: width: 200 height: 150 type: 'contain' crop: width: 200 height: 150 x: 0 y: 0 format: 'png' rotate: 'auto' large: original: true // upload original image without image processing gallery: // ... ;
In the above config, item and gallery are variants. thumb and large are presets. Each preset has an options object which is a graphicsmagick-stream config object.
preset options
-
options
- An object that is passed to graphicsmagick. See what options are available here -
rename
- A function that accepts an objectfile
as an argument. It has the following properties:name
,size
,type
andpath
. It is called before uploading each file.Example:
variantsitemthumb {return 'users/1/thumb/' + filename;};var imager = variantsitem ...; -
original
- A true value. If this option is set, the original image will be uploaded without any image processing.
storages
exportsstorages = local: provider: 'local' path: '/tmp' mode: 0777 rackspace: provider: 'rackspace' username: processenvIMAGER_RACKSPACE_USERNAME apiKey: processenvIMAGER_RACKSPACE_KEY authUrl: 'https://lon.auth.api.rackspacecloud.com' region: 'IAD' // https://github.com/pkgcloud/pkgcloud/issues/276 container: processenvIMAGER_RACKSPACE_CONTAINER amazon: provider: 'amazon' key: processenvIMAGER_S3_KEY keyId: processenvIMAGER_S3_KEYID container: processenvIMAGER_S3_BUCKET
Usage
var Imager = ;var config = ;var imager = configvariantsitem configstoragesamazon;// You can also pass only the storage without a variant which will simply// upload the original image// new Imager(storages.amazon)
API
.upload(files, callback)
files
is an array of files or a single file. A file can be a file object, absolute file path pointing a local file or base64 encoded image data. callback
accepts err
and an object containing the array of uploaded images.
var config = ;var imager = configvariantsitem configstoragesamazon;imager;
.remove(files, callback)
files
is an array of files or a single file. A file should be the file name of the image on the storage. callback
accepts err
as an argument.
var config = ;var imager = configstoragesamazon;var files = 'file-1.png'; // or just 'file-1.png'imager;
.regenerate()
Tests
$ npm test
TODO
- Support base64 image uploads
Implement.remove()
- Implement
.regenerate()
- Test the api's for rackspace
License
MIT