Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imagecache

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagecache

Lightweight image generation module based on CamanJS and inspired by Drupal's image styles.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Latest release on NPM Codeship Status for voidberg/imagecache codecov.io Commitizen friendly semantic-release David-dm.org David-dm.org MIT License

#Imagecache

What is it?

Node image generation module based on CamanJS and inspired by Drupal's image styles.

Installation

Linux prerequisites

  • aptitude install libcairo-dev libgif-dev libjpeg-dev

Mac OS X prerequisites

It's quite painful, be warned.

Usage

var presets = require('./presets.js');
var ImageCache = require('imagecache');

var imagecache = new ImageCache(presets);

imagecache.render('./in.png', 'preset_one', function (err, image) {
  // Save the image
  image.save('out_s_crop_teaser.png');

  // or

  // Get a buffer, stream it etc
  image.canvas.toBuffer();
})

Presets structure

{
  preset_one: {
    presetname: 'preset_one',
    actions: [
      {
        action: 'scale_and_crop',
        config: {
          width: 100,
          height: 300
        }
      },
      {
        action: 'define_canvas',
        config: {
          color: '#333333',
          exact: {
            width: 400,
            height: 400,
            xpos: 'center',
            ypos: 'center'
          }
        }
      }
    ]
  },
  preset_two: {
    presetname: 'preset_two',
    actions: [
      {
        action: 'scale_and_crop',
        config: {
          width: 70,
          height: 70,
        }
      }
    ]
  }
}

Creating plugins

Breeze is used for plugin management. There are two types of plugins available:

  • Utility plugins that add functions to be used by other plugins. For example see plugins/_converters.js that adds utility functions for parsing parameters that are used by all other plugins.
  • Action plugins that expose one or more functions that implement actions.

For example, a plugin that implements the sharpen action will attach a sharpen function to the plugin registry. The function signature is image, config, callback where image is the CamanJS object, config is the action configuration from the preset and callback is the function that triggers the completion of the action.

var self = module.exports = {
  attach: function (options) {
    this.sharpen = function (image, config, callback) {
      var value = this.convertInt(config.value);

      if (value > 100) {
        value = 100;
      }
      if (value < 0) {
        value = 0;
      }

      image.sharpen(value);
      callback();
    };
  }
};

##Imagecache actions:

  • Brightness [✓]
  • Crop [✓]
  • Define canvas [✓]
  • Desaturate [✓]
  • Negative image [✓]
  • Resize [✓]
  • Scale [✓]
  • Scale and crop [✓]
  • Sharpen [✓]
  • Contrast [✓]
  • Clip [✓]
  • Colorize [✓]
  • Exposure [✓]
  • Gamma [✓]
  • Hue [✓]
  • Noise [✓]
  • Saturation [✓]
  • Sepia [✓]
  • Vibrance [✓]
  • Curves [✓]
  • Overlay (watermark) [✓]
  • CamanJS filters (vintage, lomo, clarity, sinCity, sunrise, crossProcess, orangePeel, love, grungy, jarques, pinhole, oldBoot, glowingSun, hazyDays, herMajesty, nostalgia, hemingway, concentrate) [✓]

Legend:

  • [✓] - Implemented
  • [✗] - Will not be implemented
  • [] - Not implemented yet

Keywords

FAQs

Package last updated on 02 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc