node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Pipe CouchDB documents through ImageMagicks convert.


var stream = require('couchmagick-stream');
var es = require('event-stream');
var request = require('request').defaults({ json: true });
var couch = 'http://localhost:5984/mydb';
var config = {
  versions: {
    thumbnail: {
      args: [
        "-resize", "x100"
  request.get(couch + '/_all_docs', { qs: { include_docs: true } }),
  stream(couch, { thumbs: config }), map(data, done) {
    done(null, data.response);

See examples/posts.js for an advanced usage example.


There are two kinds of filters which you can define: one operates on doc level and one on version level.

Document Filter

This filter is called with one argument: document.

Version Filter

This filter is called with two arguments, document and attachment name.


Content-Type of the resulting attachment. Default is image/jpeg.


The document id where the version is stored. Defaults to {id}/{version}.

Can have the following placeholders:

  • id - the original doc id
  • parts - array of the id splitted at /
  • version - name of the version


The attachment name of the version. Default is {basename}-{version}{extname}.

Can have placeholders:

  • id - the original doc id
  • parts - array of the id splitted at /
  • version - name of the version
  • name - original attachment name, eg this/is/my-image.jpg
  • extname - file extenstion of the original attachment name, eg .jpg
  • basename - basename without extension, eg my-image
  • dirname - directory name, eg this/is
  • version - name of the version


Array of argument strings for ImageMagicks convert.

The default is ['-', 'jpg:-'], which means that ImageMagick converts the image to jpg. You can see that we use convert with pipes for in- and output.

See ImageMagick Convert Command-line Tool for a comprehensive list of options.


couchmagick-stream accepts an optional options object as third parameter:

  • concurrency - Number of simultanous processes. Default is 1.
  • convert_process_timeout - Timeout for convert process. Default is 1 minute.


You can run an example (examples/thumbnails.js):

node examples/thumbnails.js http://localhost:5984/mydb


Lint your code with npm run jshint

(c) 2013 Johannes J. Schmidt, null2 GmbH