• Stars
    star
    267
  • Rank 153,621 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[not maintained anymore] A node.js module to resize, crop and upload images to Rackspace cloudfiles and Amazon S3

Build Status Gittip Dependencies

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.

Please use [email protected] which is stable. The 1.0.0-alpha releases are unstable and not recommended for production.

Imager

A node module to resize, crop and upload images (with different variants and presets) to the cloud.

Dependencies

  1. node >= 0.11.12 with --harmony flag
  2. 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

exports.variants = {
  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 object file as an argument. It has the following properties: name, size, type and path. It is called before uploading each file.

    Example:

    variants.item.thumb.rename = function (file) {
      return 'users/1/thumb/' + file.name;
    };
    var imager = new Imager(variants.item, ...);
  • original - A true value. If this option is set, the original image will be uploaded without any image processing.

storages

exports.storages = {
  local: {
    provider: 'local',
    path: '/tmp',
    mode: 0777
  },
  rackspace: {
    provider: 'rackspace',
    username: process.env.IMAGER_RACKSPACE_USERNAME,
    apiKey: process.env.IMAGER_RACKSPACE_KEY,
    authUrl: 'https://lon.auth.api.rackspacecloud.com',
    region: 'IAD', // https://github.com/pkgcloud/pkgcloud/issues/276
    container: process.env.IMAGER_RACKSPACE_CONTAINER
  },
  amazon: {
    provider: 'amazon',
    key: process.env.IMAGER_S3_KEY,
    keyId: process.env.IMAGER_S3_KEYID,
    container: process.env.IMAGER_S3_BUCKET
  }
}

Usage

var Imager = require('imager');
var config = require('./imager-config.js');
var imager = new Imager(config.variants.item, config.storages.amazon);
// 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 = require('./imager-config.js');
var imager = new Imager(config.variants.item, config.storages.amazon);
imager.upload(files, function (err, avatar) {
  // avatar =>
  // {
  //   thumb: [ 'https://fudge.s3.amazonaws.com/user/1/thumb/image-1.png', ],
  //   large: [ 'https://fudge.s3.amazonaws.com/user/1/large/image-1.png', ]
  // }
});

.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 = require('./imager-config.js');
var imager = new Imager(config.storages.amazon);
var files = ['file-1.png']; // or just 'file-1.png'
imager.remove(files, function (err) {

});

.regenerate()

Tests

$ npm test

TODO

  • Support base64 image uploads
  • Implement .remove()
  • Implement .regenerate()
  • Test the api's for rackspace

License

MIT

More Repositories

1

node-express-mongoose-demo

A simple demo app using node and mongodb for beginners (with docker)
JavaScript
5,120
star
2

node-express-mongoose

A boilerplate application for building web apps using node and mongodb
JavaScript
1,426
star
3

go-gin-mgo-demo

A demo CRUD application in golang using the popular gin-gonic framework
Go
161
star
4

node-notifier

A simple node.js module to handle all the application level notifications (apple push notifications and mails)
JavaScript
86
star
5

node-view-helpers

expressjs view helper methods
JavaScript
83
star
6

mongoose-migrate

mongodb migrations for node
JavaScript
67
star
7

node-genem

(not maintained) Opinionated MVC generator for NodeJS that uses express and mongoose.
JavaScript
54
star
8

mongoose-user

Some generic methods, statics and virtuals used for user schemas
JavaScript
47
star
9

lm.js

localStorage manager.
JavaScript
30
star
10

gedit3-plugins

gedit plugins compatible with v3
Python
6
star
11

go-martini-mgo-demo

A simple CRUD app in golang and mongodb using martini, mgo and godep
Go
5
star
12

ab

A boilerplate for building angular apps with bower, gulp, angular-ui, bootstrap and less.
JavaScript
5
star
13

tomdoc

modified version of tomdoc
Ruby
4
star
14

my-gedit-settings

My gedit2 plugins and configurations
Python
4
star
15

browserify-example

browserify example for building client side apps using ES6
JavaScript
4
star
16

mongoose-load-list

easy queries with mongoose
JavaScript
4
star
17

install-scripts

install libraries and softwares on a fresh ubuntu
Shell
3
star
18

geekhunt

Search for geeks on github
JavaScript
3
star
19

omniauth-on-heroku

Omniauth with authlogic on heroku
Ruby
3
star
20

reboil-demo

React boilerplate
JavaScript
3
star
21

gokoa-demo

A demo using koa and mongoose to build apis.
JavaScript
2
star
22

sublime-settings

my sublimetext settings
2
star
23

gokoa

A boilerplate for building web apps using koajs.
JavaScript
2
star
24

delete-blank-lines.tmbundle

delete blank lines textmate bundle
2
star
25

madhums.github.io

SCSS
2
star
26

imager-cli

cli for imager
JavaScript
1
star
27

ts-aggregate

A simple wrapper for aggregating time series data for mongodb.
JavaScript
1
star
28

browsetime

A chrome/brave extension to monitor how much time you spend on websites
JavaScript
1
star
29

dinner-quest-api

JavaScript
1
star
30

analyze-text

Analyze text using Sentiment Analysis
JavaScript
1
star
31

aj

Command to add .jshintrc
JavaScript
1
star
32

clean-linkedin-feed

A chrome/brave extension to hide social media content (images, videos, presentations and link previews) in linkedin feed.
JavaScript
1
star
33

nlib

CLI helper to set up new node library
JavaScript
1
star