npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imager

v1.0.0-alpha1

Published

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

Downloads

180

Readme

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.

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