|
| 1 | +[](https://waffle.io/voidberg/imagecache) |
| 2 | +[](https://www.npmjs.com/package/imagecache) |
| 3 | +[](https://codeship.com/projects/106113) |
| 4 | +[](http://codecov.io/github/voidberg/imagecache?branch=master) |
| 5 | +[](http://commitizen.github.io/cz-cli/) |
| 6 | +[](https://github.com/semantic-release/semantic-release) |
| 7 | +[](https://david-dm.org/voidberg/imagecache#info=dependencies&view=table) |
| 8 | +[](https://david-dm.org/voidberg/imagecache#info=devDependencies&view=table) |
| 9 | +[](https://opensource.org/licenses/MIT) |
| 10 | + |
| 11 | +#Imagecache |
| 12 | +--- |
| 13 | + |
| 14 | +## What is it? |
| 15 | + |
| 16 | +Node image generation module based on CamanJS and inspired by Drupal's image styles. |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +### Linux prerequisites |
| 21 | +* `aptitude install libcairo-dev libgif-dev libjpeg-dev` |
| 22 | + |
| 23 | +### Mac OS X prerequisites |
| 24 | + |
| 25 | +It's quite painful, be warned. |
| 26 | + |
| 27 | +* Install X Server (http://xquartz.macosforge.org/trac/wiki/X112.7.6). |
| 28 | +* Install X Code (https://itunes.apple.com/gb/app/xcode/id497799835?mt=12) and command line tools. |
| 29 | +* Install Homebrew (https://github.com/Homebrew/homebrew/wiki/Installation). |
| 30 | +* `export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig`. |
| 31 | +* Install Cairo from source: `brew install --build-from-source cairo`. |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +``` |
| 36 | +var presets = require('./presets.js'); |
| 37 | +var ImageCache = require('imagecache'); |
| 38 | +
|
| 39 | +var imagecache = new ImageCache(presets); |
| 40 | +
|
| 41 | +imagecache.render('./in.png', 'preset_one', function (err, image) { |
| 42 | + // Save the image |
| 43 | + image.save('out_s_crop_teaser.png'); |
| 44 | +
|
| 45 | + // or |
| 46 | +
|
| 47 | + // Get a buffer, stream it etc |
| 48 | + image.canvas.toBuffer(); |
| 49 | +}) |
| 50 | +``` |
| 51 | + |
| 52 | +## Presets structure |
| 53 | + |
| 54 | +``` |
| 55 | +{ |
| 56 | + preset_one: { |
| 57 | + presetname: 'preset_one', |
| 58 | + actions: [ |
| 59 | + { |
| 60 | + action: 'scale_and_crop', |
| 61 | + config: { |
| 62 | + width: 100, |
| 63 | + height: 300 |
| 64 | + } |
| 65 | + }, |
| 66 | + { |
| 67 | + action: 'define_canvas', |
| 68 | + config: { |
| 69 | + color: '#333333', |
| 70 | + exact: { |
| 71 | + width: 400, |
| 72 | + height: 400, |
| 73 | + xpos: 'center', |
| 74 | + ypos: 'center' |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + preset_two: { |
| 81 | + presetname: 'preset_two', |
| 82 | + actions: [ |
| 83 | + { |
| 84 | + action: 'scale_and_crop', |
| 85 | + config: { |
| 86 | + width: 70, |
| 87 | + height: 70, |
| 88 | + } |
| 89 | + } |
| 90 | + ] |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +### Creating plugins |
| 96 | +Breeze is used for plugin management. There are two types of plugins available: |
| 97 | + |
| 98 | +* 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. |
| 99 | +* Action plugins that expose one or more functions that implement actions. |
| 100 | + |
| 101 | +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. |
| 102 | + |
| 103 | +``` |
| 104 | +var self = module.exports = { |
| 105 | + attach: function (options) { |
| 106 | + this.sharpen = function (image, config, callback) { |
| 107 | + var value = this.convertInt(config.value); |
| 108 | +
|
| 109 | + if (value > 100) { |
| 110 | + value = 100; |
| 111 | + } |
| 112 | + if (value < 0) { |
| 113 | + value = 0; |
| 114 | + } |
| 115 | +
|
| 116 | + image.sharpen(value); |
| 117 | + callback(); |
| 118 | + }; |
| 119 | + } |
| 120 | +}; |
| 121 | +``` |
| 122 | + |
| 123 | +##Imagecache actions: |
| 124 | + |
| 125 | + |
| 126 | +* Brightness [✓] |
| 127 | +* Crop [✓] |
| 128 | +* Define canvas [✓] |
| 129 | +* Desaturate [✓] |
| 130 | +* Negative image [✓] |
| 131 | +* Resize [✓] |
| 132 | +* Scale [✓] |
| 133 | +* Scale and crop [✓] |
| 134 | +* Sharpen [✓] |
| 135 | +* Contrast [✓] |
| 136 | +* Clip [✓] |
| 137 | +* Colorize [✓] |
| 138 | +* Exposure [✓] |
| 139 | +* Gamma [✓] |
| 140 | +* Hue [✓] |
| 141 | +* Noise [✓] |
| 142 | +* Saturation [✓] |
| 143 | +* Sepia [✓] |
| 144 | +* Vibrance [✓] |
| 145 | +* Curves [✓] |
| 146 | +* Overlay (watermark) [✓] |
| 147 | +* CamanJS filters (vintage, lomo, clarity, sinCity, sunrise, crossProcess, orangePeel, love, grungy, jarques, pinhole, oldBoot, glowingSun, hazyDays, herMajesty, nostalgia, hemingway, concentrate) [✓] |
| 148 | + |
| 149 | +Legend: |
| 150 | + |
| 151 | +* [✓] - Implemented |
| 152 | +* [✗] - Will not be implemented |
| 153 | +* [] - Not implemented yet |
0 commit comments