The JavaScript Image Manipulation Program, now with 100% more boing.
Load an image, squish it, spin it, melt it, save it. Jimp is just JavaScript, so it runs in Node, in the browser, and in workers, with no native bits to compile.
Tip: every Jimp method changes the image in place and returns it, so you can call them one after another, or chain them.
The Guides
Notebook pages for every part of Jimp. Pick a sticker tab up top, or flip through with the arrows at the bottom.
The Sticker Book
The API reference, one sticker per method. Each thumbnail was made by Jimp just now, right in your browser. Click a sticker to use it in the Paint Box.
Jimp (JavaScript Image Manipulation Program) is a package that makes it easy to load and manipulate images in the browser and Node.js. It aims to run anywhere that JavaScript is supported.
Jimp is built on JavaScript implementations of image formats. These implementations are not optimized for performance and may allocate a lot of memory before using.
By default JPEG, GIF, TIFF and BMP images larger than 100 megapixels are rejected. See Reading Large Images to raise the limits.
Jimp can be used anywhere that JavaScript is supported. It can be used in the browser, in Node.js, or in a web worker. Jimp comes with a pre-bundled browser version. To use it, simply import jimp.
This whole page is built that way: the Paint Box loads Jimp straight from a CDN.
From a CDN
The browser build at dist/browser/index.js is a self-contained ES module, so you can import it straight from a CDN without a bundler.
Jimp decodes images with JavaScript implementations of each format. To avoid running out of memory on huge or malicious files, most decoders refuse images above a size limit. If you need to read an image larger than the defaults, pass decode options to Jimp.read or Jimp.fromBuffer.
Passing decode options
The second argument is an object keyed by MIME type. Jimp detects the image's type and passes only the matching options to its decoder, so you can set options for several formats at once.
When an image is over a limit, decoding throws an error instead of allocating memory for it. Resolution limits are in megapixels, so a 100 megapixel limit allows a 10,000 × 10,000 image.
Cameras and phones store metadata in JPEG files as EXIF: the camera make and model, the resolution, the date, the orientation and often the GPS location. Jimp reads EXIF from JPEG images.
Auto-rotation on read
When Jimp.read loads a JPEG with an orientation other than 1, Jimp rotates and flips the pixels so the image is upright, then sets the orientation to 1.
There are two types of plugins you can write for Jimp: image format plugins and image manipulation plugins. You can combine plugins to create a Custom Jimp.
Image manipulation plugins
An image manipulation method takes an image as its first argument, does something to it, and returns the image. Every tool in the Paint Box is one of these.
import { JimpClass } from "@jimp/types";
export const methods = {
/** Make every pixel a bit more purple */
purplify<I extends JimpClass>(image: I) {
image.scan((x, y, idx) => {
image.bitmap.data[idx + 2] = 255;
});
return image;
},
};
Image format plugins
Format plugins load and save one image format. They are made of two functions: encode and decode.
If you don't want to use all the default plugins included in the jimp package, you can create a custom Jimp with createJimp.
Creating a custom Jimp
import { createJimp } from "@jimp/core";
import png from "@jimp/js-png";
import * as resize from "@jimp/plugin-resize";
const MyJimp = createJimp({
plugins: [resize.methods],
formats: [png],
});
const image = await MyJimp.read("test/image.png");
image.resize({ w: 100 });
await image.write("test/output.png");
Jimp's packages import Buffer from the buffer package, so a custom Jimp works in browsers and Cloudflare Workers without a polyfill.
The goals of v1 were to make Jimp easier to use in any environment, and to make its API more consistent.
Async all the way
All export methods are async now, and callbacks are gone: getBufferAsync is getBuffer, getBase64Async is getBase64, and writeAsync is write.
The default build of Jimp only includes image formats written in JavaScript. To use WEBP (and anything else without a JS implementation) add a WASM format plugin and create a custom Jimp.
npm install jimp @jimp/core @jimp/wasm-webp
import { createJimp } from "@jimp/core";
import { defaultFormats, defaultPlugins } from "jimp";
import webp from "@jimp/wasm-webp";
// A custom jimp that supports webp
const Jimp = createJimp({
formats: [...defaultFormats, webp],
plugins: defaultPlugins,
});
There are WASM plugins for AVIF, JPEG, PNG and WEBP. Your bundler needs to serve their .wasm files, so check the full guide for Vite and webpack setup.