0.22.12 • Published 2 months ago

@jimp/plugin-color v0.22.12

Weekly downloads
1,120,144
License
MIT
Repository
github
Last release
2 months ago

Bitmap manipulation to adjust the color in an image.

color

Apply multiple color modification rules

  • @param {array} actions list of color modification rules, in following format: { apply: '', params: }
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.color([{ apply: "red", params: [100] }]);
}

main();

Jimp supports advanced colour manipulation using a single method as follows:

image.color([
  { apply: "hue", params: [-90] },
  { apply: "lighten", params: [50] },
  { apply: "xor", params: ["#06D"] },
]);

The method supports the following modifiers:

ModifierDescription
lighten {amount}Lighten the color a given amount, from 0 to 100. Providing 100 will always return white (works through TinyColor)
brighten {amount}Brighten the color a given amount, from 0 to 100 (works through TinyColor)
darken {amount}Darken the color a given amount, from 0 to 100. Providing 100 will always return black (works through TinyColor)
desaturate {amount}Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale (works through TinyColor)
saturate {amount}Saturate the color a given amount, from 0 to 100 (works through TinyColor)
greyscale {amount}Completely desaturates a color into greyscale (works through TinyColor)
spin {degree}Spin the hue a given amount, from -360 to 360. Calling with 0, 360, or -360 will do nothing - since it sets the hue back to what it was before. (works through TinyColor)
hue {degree}Alias for spin
mix {color, amount}Mixes colors by their RGB component values. Amount is opacity of overlaying color
tint {amount}Same as applying mix with white color
shade {amount}Same as applying mix with black color
xor {color}Treats the two colors as bitfields and applies an XOR operation to the red, green, and blue components
red {amount}Modify Red component by a given amount
green {amount}Modify Green component by a given amount
blue {amount}Modify Blue component by a given amount

brightness

Adjusts the brightness of the image

  • @param {number} val the amount to adjust the brightness, a number between -1 and +1
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.brightness(20);
}

main();

contrast

Adjusts the contrast of the image

  • @param {number} val the amount to adjust the contrast, a number between -1 and +1
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.contrast(70);
}

main();

posterize

Apply a posterize effect

  • @param {number} n the amount to adjust the contrast, minimum threshold is two
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.posterize(5);
}

main();

opacity

Multiplies the opacity of each pixel by a factor between 0 and 1

  • @param {number} f A number, the factor by which to multiply the opacity of each pixel
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.opacity(80);
}

main();

sepia

Applies a sepia tone to the image

  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.sepia();
}

main();

fade

Fades each pixel by a factor between 0 and 1

  • @param {number} f A number from 0 to 1. 0 will haven no effect. 1 will turn the image completely transparent.
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.fade(0.7);
}

main();

convolution

Sum neighbor pixels weighted by the kernel matrix. You can find a nice explanation with examples at GIMP's Convolution Matrix plugin

  • @param {array} kernel a matrix to weight the neighbors sum
  • @param {number} edgeHandling (optional) define how to sum pixels from outside the border
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.convolution(
    [
      [-1, -1, -1],
      [-1, 8, -1],
      [-1, -1, -1],
    ],
    jimp.EDGE_EXTEND
  );
}

main();

opaque

Set the alpha channel on every pixel to fully opaque

  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.opaque();
}

main();

pixelate

Pixelates the image or a region

  • @param {number} size the size of the pixels
  • @param {number} x (optional) the x position of the region to pixelate
  • @param {number} y (optional) the y position of the region to pixelate
  • @param {number} w (optional) the width of the region to pixelate
  • @param {number} h (optional) the height of the region to pixelate
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  image.pixelate(10);
}

main();

convolute

Applies a convolution kernel to the image or a region

  • @param {array} kernel the convolution kernel
  • @param {number} x (optional) the x position of the region to apply convolution to
  • @param {number} y (optional) the y position of the region to apply convolution to
  • @param {number} w (optional) the width of the region to apply convolution to
  • @param {number} h (optional) the height of the region to apply convolution to
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

async function main() {
  const image = await jimp.read("test/image.png");

  // make me better
  image.pixelate(kernal);
}

main();
0.22.12

2 months ago

0.22.11

2 months ago

0.22.10

9 months ago

0.22.9

9 months ago

0.22.8

11 months ago

0.22.7

1 year ago

0.22.6

1 year ago

0.20.1

1 year ago

0.20.0

1 year ago

0.17.2

1 year ago

0.17.3

1 year ago

0.17.4

1 year ago

0.17.5

1 year ago

0.17.6

1 year ago

0.17.7

1 year ago

0.17.8

1 year ago

0.17.9

1 year ago

0.17.0

1 year ago

0.17.1

1 year ago

0.17.10

1 year ago

0.21.3

1 year ago

0.21.2

1 year ago

0.21.1

1 year ago

0.21.0

1 year ago

0.18.0

1 year ago

0.22.5

1 year ago

0.22.4

1 year ago

0.22.3

1 year ago

0.22.2

1 year ago

0.22.1

1 year ago

0.22.0

1 year ago

0.16.10

1 year ago

0.16.11

1 year ago

0.16.12

1 year ago

0.16.13

1 year ago

0.16.3

1 year ago

0.16.4

1 year ago

0.16.5

1 year ago

0.16.6

1 year ago

0.16.7

1 year ago

0.16.8

1 year ago

0.16.9

1 year ago

0.20.2

1 year ago

0.19.0

1 year ago

0.16.2

2 years ago

0.16.1

4 years ago

0.15.0

4 years ago

0.16.0

4 years ago

0.14.0

4 years ago

0.13.0

4 years ago

0.12.1

4 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.4

4 years ago

0.9.5

4 years ago

0.9.3

4 years ago

0.9.0

4 years ago

0.9.1

4 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.2

5 years ago

0.6.0

5 years ago

0.5.5

5 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.10

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

6 years ago

0.3.6-alpha.6

6 years ago

0.3.6-alpha.5

6 years ago