@jimp/custom
Interface to customize jimp configuration
Last updated 5 years ago by alisowski .
MIT · Original npm · Tarball · package.json
$ npm install @jimp/custom 
SYNC missed versions from official npm registry.

@jimp/custom

Configure jimp with types and plugins.

Useful Defaults

The following wil configure a jimp instance with the same functionality as the main jimp package.

import configure from '@jimp/custom';
// all of jimp's default types
import types from '@jimp/types';
// all of jimp's default types
import plugins from '@jimp/plugins';

configure({
  types: [types],
  plugins: [plugins]
});

Available Methods

configure

Takes a Jimp configuration and applies it to @jimp/core.

Sample Jimp configuration:

import types from '@jimp/types';

import bmp from '@jimp/bmp';
import jpeg from '@jimp/types';
...

configure({
  types: [types]
})

// or

configure({
  types: [bmp, jpeg, ...]
})

Extending Jimp Further

You can use configure to add more types and plugins to a jimp multiple times.

let jimp = configure({
  types: [bmp]
});

jimp = configure(
  {
    types: [jpeg]
  },
  jimp
);

Type Definition

To define a new Jimp image type write a function the takes the current Jimp configuration. In this function you can extend Jimp's internal data structures.

This function must return and array whose first element is the mime type and second element is an array of valid file extensions.

const special = require('special-js');

const MIME_TYPE = 'image/special';

export default () => ({
  mime: [MIME_TYPE, ['spec', 'special']],

  constants: {
    MIME_SPECIAL: MIME_TYPE
  },

  decoders: {
    [MIME_TYPE]: data => special.decode(data)
  },

  encoders: {
    [MIME_TYPE]: image => special.encode(image.bitmap)
  }
});

Constants

A jimp image type can expose as many constants as it wants. Each jimp type is required to expose a mime type.

constants: {
  MIME_SPECIAL: MIME_TYPE
},

hasAlpha

A image type can define whether it supports an alpha channel.

hasAlpha: {
  MIME_SPECIAL: true
},

Decoder

A function that when supplied with a buffer should return a bitmap with height and width.

decoders: {
  [MIME_TYPE]: data => special.decode(data)
},

Encoder

A function that when supplied with a Jimp image should return an encoded buffer.

encoders: {
  [MIME_TYPE]: image => special.encode(image.bitmap)
}

Class

Add class properties and function to the Jimp constructor.

class: {
  _quality: 100,
  quality: function(n, cb) {
    if (typeof n !== 'number') {
      return throwError.call(this, 'n must be a number', cb);
    }

    if (n < 0 || n > 100) {
      return throwError.call(this, 'n must be a number 0 - 100', cb);
    }

    this._quality = Math.round(n);

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
};

Plugin Definition

Defining a plugin has access to all the same things in the type definition. Mainly plugins use just the constants and class config options.

Below is the invert plugin. If a plugin doesn return an object with constants and class, all keys are treated as class functions.

import { isNodePattern } from '@jimp/utils';

/**
 * Inverts the image
 * @param {function(Error, Jimp)} cb (optional) a callback for when complete
 * @returns {Jimp} this for chaining of methods
 */
export default () => ({
  invert(cb) {
    this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
      x,
      y,
      idx
    ) {
      this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
      this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
      this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
    });

    if (isNodePattern(cb)) {
      cb.call(this, null, this);
    }

    return this;
  }
});

Current Tags

  • 0.22.11--canary.c55989b.0                                ...           canary (9 months ago)
  • 0.22.12                                ...           latest (9 months ago)

219 Versions

  • 0.22.12                                ...           9 months ago
  • 0.22.11                                ...           9 months ago
  • 0.22.11--canary.c55989b.0                                ...           9 months ago
  • 0.22.10                                ...           a year ago
  • 0.22.9                                ...           a year ago
  • 0.22.8                                ...           2 years ago
  • 0.22.7                                ...           2 years ago
  • 0.22.6                                ...           2 years ago
  • 0.22.6--canary.1198.9324a88b87a1fc38b528af47ca707d97593dddaa.0                                ...           2 years ago
  • 0.22.5                                ...           2 years ago
  • 0.22.4                                ...           2 years ago
  • 0.22.4--canary.1187.30d10f964404705d383d7163b7d3f85baa2201b7.0                                ...           2 years ago
  • 0.22.3                                ...           2 years ago
  • 0.22.3--canary.1184.ff6583af74ba85d9555c36db2844886e269feb16.0                                ...           2 years ago
  • 0.22.2                                ...           2 years ago
  • 0.22.1                                ...           2 years ago
  • 0.22.1--canary.1173.30a931db5f6552c59e4c99f41fdb9e2b9ccf8291.0                                ...           2 years ago
  • 0.22.1--canary.1169.6db477d088d28aea43b31d9ca8b0eaf74dc511d1.0                                ...           2 years ago
  • 0.22.0                                ...           2 years ago
  • 0.21.4--canary.1163.d07ed6254d130e2995d24101e93427ec091016e6.0                                ...           2 years ago
  • 0.21.4--canary.1163.7b9287fff1036ae67190d5ea3a8dec9926373a63.0                                ...           2 years ago
  • 0.21.4--canary.1163.6a6ae39e83bd731ccd25120a160a75b32273f9bd.0                                ...           2 years ago
  • 0.21.4--canary.1163.a26f5b300ee88c2fadb9909dd390cb4380b32a42.0                                ...           2 years ago
  • 0.21.3                                ...           2 years ago
  • 0.21.2                                ...           2 years ago
  • 0.21.2--canary.1156.1f8a92bfc1cbc6b5f3ad2490d0ec86710c81f635.0                                ...           2 years ago
  • 0.21.2--canary.1156.ba9fec9d0c9109924b4a5acab31bcaef8159a610.0                                ...           2 years ago
  • 0.21.2--canary.1156.8b2cc45.0                                ...           2 years ago
  • 0.21.1                                ...           2 years ago
  • 0.21.1--canary.1153.3cc6d7b.0                                ...           2 years ago
  • 0.21.0                                ...           2 years ago
  • 0.21.0--canary.1149.a81f653.0                                ...           2 years ago
  • 0.21.0--canary.1149.3239903.0                                ...           2 years ago
  • 0.20.2                                ...           2 years ago
  • 0.20.1                                ...           2 years ago
  • 0.20.0                                ...           2 years ago
  • 0.19.0                                ...           2 years ago
  • 0.17.9--canary.1144.3455afd.0                                ...           2 years ago
  • 0.17.9--canary.1143.90575e6.0                                ...           2 years ago
  • 0.17.9--canary.fc042e5.0                                ...           2 years ago
  • 0.18.0                                ...           2 years ago
  • 0.17.9--canary.1141.cd4d455.0                                ...           2 years ago
  • 0.17.10                                ...           2 years ago
  • 0.17.9--canary.1140.e3ff49d.0                                ...           2 years ago
  • 0.17.9--canary.1140.4042b43.0                                ...           2 years ago
  • 0.17.9--canary.1140.831bc3c.0                                ...           2 years ago
  • 0.17.9                                ...           2 years ago
  • 0.17.8                                ...           2 years ago
  • 0.17.8--canary.1137.476d7bd.0                                ...           2 years ago
  • 0.17.7                                ...           2 years ago
  • 0.17.6                                ...           2 years ago
  • 0.17.6--canary.1137.5e459dc.0                                ...           2 years ago
  • 0.17.6--canary.cd893f3.0                                ...           2 years ago
  • 0.17.6--canary.1cb89cf.0                                ...           2 years ago
  • 0.17.5                                ...           2 years ago
  • 0.17.4                                ...           2 years ago
  • 0.17.3                                ...           2 years ago
  • 0.17.3--canary.1136.7f5f5d8.0                                ...           2 years ago
  • 0.17.2                                ...           2 years ago
  • 0.18.0--canary.1135.911ed04.0                                ...           2 years ago
  • 0.17.1                                ...           2 years ago
  • 0.17.1--canary.1134.e007a48.0                                ...           2 years ago
  • 0.17.1--canary.e22c14a.0                                ...           2 years ago
  • 0.18.0--canary.1133.54bf269.0                                ...           2 years ago
  • 0.17.0                                ...           2 years ago
  • 0.17.0--canary.1131.af3cb94.0                                ...           2 years ago
  • 0.16.13                                ...           2 years ago
  • 0.16.12                                ...           2 years ago
  • 0.16.11                                ...           2 years ago
  • 0.16.10                                ...           2 years ago
  • 0.16.9                                ...           2 years ago
  • 0.16.8                                ...           2 years ago
  • 0.16.7                                ...           2 years ago
  • 0.16.6                                ...           2 years ago
  • 0.16.5                                ...           2 years ago
  • 0.16.4                                ...           2 years ago
  • 0.16.3                                ...           2 years ago
  • 0.16.3-canary.993.1592.0                                ...           2 years ago
  • 0.16.3-canary.1045.1590.0                                ...           2 years ago
  • 0.16.3-canary.1082.1591.0                                ...           2 years ago
  • 0.16.3-canary.1040.1589.0                                ...           2 years ago
  • 0.16.3-canary.999.1588.0                                ...           2 years ago
  • 0.16.3-canary.1085.1581.0                                ...           2 years ago
  • 0.16.3-canary.1014.1579.0                                ...           2 years ago
  • 0.16.3-canary.1125.1580.0                                ...           2 years ago
  • 0.16.3-canary.1113.1404.0                                ...           2 years ago
  • 0.16.3-canary.1109.1388.0                                ...           2 years ago
  • 0.16.3-canary.1108.1382.0                                ...           2 years ago
  • 0.16.3-canary.1100.1371.0                                ...           2 years ago
  • 0.16.2                                ...           2 years ago
  • 0.16.2-canary.1094.1345.0                                ...           2 years ago
  • 0.16.2-canary.1093.1332.0                                ...           2 years ago
  • 0.16.2-canary.1086.1311.0                                ...           2 years ago
  • 0.16.2-canary.1084.1305.0                                ...           2 years ago
  • 0.16.2-canary.1082.1294.0                                ...           3 years ago
  • 0.16.2-canary.1080.1288.0                                ...           3 years ago
  • 0.16.2-canary.1073.1276.0                                ...           3 years ago
  • 0.16.2-canary.1070.1265.0                                ...           3 years ago
  • 0.16.2-canary.1052.1235.0                                ...           3 years ago
  • 0.16.2-canary.1051.1228.0                                ...           3 years ago
  • 0.16.2-canary.1045.1221.0                                ...           3 years ago
  • 0.16.2-canary.1016.1185.0                                ...           3 years ago
  • 0.16.2-canary.1008.1164.0                                ...           4 years ago
  • 0.16.2-canary.984.1126.0                                ...           4 years ago
  • 0.16.2-canary.969.1115.0                                ...           4 years ago
  • 0.16.2-canary.964.1101.0                                ...           4 years ago
  • 0.16.2-canary.956.1095.0                                ...           4 years ago
  • 0.16.2-canary.947.1077.0                                ...           4 years ago
  • 0.16.2-canary.938.1059.0                                ...           4 years ago
  • 0.16.2-canary.934.1053.0                                ...           4 years ago
  • 0.16.2-canary.919.1052.0                                ...           4 years ago
  • 0.16.1                                ...           4 years ago
  • 0.16.0                                ...           4 years ago
  • 0.15.1-canary.924.1021.0                                ...           4 years ago
  • 0.15.0                                ...           4 years ago
  • 0.14.1-canary.919.1005.0                                ...           4 years ago
  • 0.14.1-canary.911.993.0                                ...           4 years ago
  • 0.14.0                                ...           4 years ago
  • 0.14.0-canary.904.976.0                                ...           4 years ago
  • 0.13.0-canary.899.964.0                                ...           4 years ago
  • 0.13.0                                ...           4 years ago
  • 0.12.2-canary.899.952.0                                ...           4 years ago
  • 0.12.1                                ...           4 years ago
  • 0.12.1-canary.892.924.0                                ...           4 years ago
  • 0.12.0                                ...           4 years ago
  • 0.11.1-canary.891.908.0                                ...           4 years ago
  • 0.11.0                                ...           4 years ago
  • 0.10.5-canary.882.886.0                                ...           5 years ago
  • 0.10.4-canary.882.884.0                                ...           5 years ago
  • 0.10.4-canary.882.885.0                                ...           5 years ago
  • 0.10.3                                ...           5 years ago
  • 0.10.2                                ...           5 years ago
  • 0.10.2-canary.875.842.0                                ...           5 years ago
  • 0.10.1                                ...           5 years ago
  • 0.10.1-canary.870.821.0                                ...           5 years ago
  • 0.10.0                                ...           5 years ago
  • 0.9.9-canary.868.799.0                                ...           5 years ago
  • 0.9.9-canary.867.792.0                                ...           5 years ago
  • 0.9.8                                ...           5 years ago
  • 0.9.8-canary.866.767.0                                ...           5 years ago
  • 0.9.7                                ...           5 years ago
  • 0.9.7-canary.854.725.0                                ...           5 years ago
  • 0.9.6                                ...           5 years ago
  • 0.9.6-canary.860.700.0                                ...           5 years ago
  • 0.9.6-canary.857.681.0                                ...           5 years ago
  • 0.9.6-canary.858.667.0                                ...           5 years ago
  • 0.9.5                                ...           5 years ago
  • 0.9.4                                ...           5 years ago
  • 0.9.4-canary.845.627.0                                ...           5 years ago
  • 0.9.4-canary.841.620.0                                ...           5 years ago
  • 0.9.4-canary.838.613.0                                ...           5 years ago
  • 0.9.4-canary.832.606.0                                ...           5 years ago
  • 0.9.3-canary.825.599.0                                ...           5 years ago
  • 0.9.3                                ...           5 years ago
  • 0.9.3-canary.825.584.0                                ...           5 years ago
  • 0.9.2-canary.815.538.0                                ...           5 years ago
  • 0.9.1                                ...           5 years ago
  • 0.9.0                                ...           5 years ago
  • 0.8.6-canary.815.502.0                                ...           5 years ago
  • 0.8.6-canary.818.495.0                                ...           5 years ago
  • 0.8.6-canary.815.488.0                                ...           5 years ago
  • 0.8.6-canary.810.481.0                                ...           5 years ago
  • 0.8.5                                ...           5 years ago
  • 0.8.1-canary.791.466.0                                ...           5 years ago
  • 0.8.1-canary.789.460.0                                ...           5 years ago
  • 0.8.5-canary.799.447.0                                ...           5 years ago
  • 0.8.5-canary.1.b147e81.0                                ...           5 years ago
  • 0.8.5-canary.b147e81.0                                ...           5 years ago
  • 0.8.5-canary.753c2c9.0                                ...           5 years ago
  • 0.8.5-canary.800.426.0                                ...           5 years ago
  • 0.8.4                                ...           5 years ago
  • 0.8.4-canary.798.377.0                                ...           5 years ago
  • 0.8.3                                ...           5 years ago
  • 0.8.2-canary.792.360.0                                ...           5 years ago
  • 0.8.2-canary.792.353.0                                ...           5 years ago
  • 0.8.2-canary.792.349.0                                ...           5 years ago
  • 0.8.2-canary.792.339.0                                ...           5 years ago
  • 0.8.2-canary.792.332.0                                ...           5 years ago
  • 0.8.2                                ...           5 years ago
  • 0.8.2-canary.794.308.0                                ...           5 years ago
  • 0.8.1-canary.789.301.0                                ...           5 years ago
  • 0.8.2-canary.792.290.0                                ...           5 years ago
  • 0.8.2-canary.792.283.0                                ...           5 years ago
  • 0.8.1-canary.791.276.0                                ...           5 years ago
  • 0.8.1                                ...           5 years ago
  • 0.8.1-canary.786.262.0                                ...           5 years ago
  • 0.8.1-canary.786.242.0                                ...           5 years ago
  • 0.8.1-canary.786.232.0                                ...           5 years ago
  • 0.8.1-canary.786.223.0                                ...           5 years ago
  • 0.8.1-canary.786.217.0                                ...           5 years ago
  • 0.8.1-canary.786.211.0                                ...           5 years ago
  • 0.8.0                                ...           5 years ago
  • 0.7.1-canary.770.193.0                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.8                                ...           5 years ago
  • 0.6.8-canary.783.163.0                                ...           5 years ago
  • 0.6.7-canary.783.157.0                                ...           5 years ago
  • 0.6.7                                ...           5 years ago
  • 0.6.6                                ...           5 years ago
  • 0.6.5                                ...           5 years ago
  • 0.6.5-canary.784.124.0                                ...           5 years ago
  • 0.6.5-canary.784.118.0                                ...           5 years ago
  • 0.6.5-canary.eeb6481.0                                ...           5 years ago
  • 0.6.5-canary.4564f3c.0                                ...           5 years ago
  • 0.6.4                                ...           6 years ago
  • 0.6.2                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.4                                ...           6 years ago
  • 0.5.3                                ...           6 years ago
  • 0.5.2                                ...           6 years ago
  • 0.5.1                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.9                                ...           6 years ago
  • 0.3.9-alpha.0                                ...           6 years ago
  • 0.3.8                                ...           6 years ago
  • 0.3.7                                ...           6 years ago
  • 0.3.6-alpha.6                                ...           6 years ago
  • 0.3.6-alpha.5                                ...           6 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE