Skip to content
docs
GitHub 4.5M /week v2.2.0
Guide

Getting Started

Install Jimp, then load, edit and save your first image in Node.js or the browser.

Jimp (JavaScript Image Manipulation Program) reads, edits and writes images in Node.js and the browser. It’s written entirely in JavaScript, so there are no native dependencies to install or compile. This guide walks through a first program: install Jimp, load an image, change it, and save the result.

Every Jimp program follows the same three steps:

  1. Load an image with Jimp.read, or create a blank one with new Jimp().
  2. Edit it with methods such as resize, crop or greyscale.
  3. Save it with write, or encode it with getBuffer or getBase64.

Install

Add the jimp package to your project:

npm install jimp

Jimp 2.0 needs Node.js 22 or later. The package works with both import and require, and ships its own TypeScript types.

index.ts
import { Jimp } from "jimp";

Jimp is a named export. There’s no default export as there was in v0. If you’re upgrading, see Migrate to v2 from 1.x, or Migrate to v1 from v0.

Load an image

Jimp.read loads an image and returns a promise for it. Jimp detects the format from the file’s contents, not its name.

index.ts
import { Jimp } from "jimp";
// A path on disk
const image = await Jimp.read("photos/dice.png");
// A URL, downloaded with fetch
const remote = await Jimp.read("https://jimp-dev.github.io/jimp/dice.png");
console.log(image.width, image.height, image.mime); // 800 600 "image/png"

In Node.js, Jimp.read fetches strings that start with http:, https:, data: or blob:, and reads any other string as a file path. It also accepts a Buffer, ArrayBuffer, Uint8Array or Blob. When you already have the bytes in memory, Jimp.fromBuffer does the same thing. To build an image from scratch, pass a size and an optional fill color to new Jimp():

index.ts
const canvas = new Jimp({ width: 400, height: 300, color: 0xffffffff });

Out of the box Jimp reads and writes PNG, JPEG, GIF, BMP, TIFF and ICO, and reads CUR. WebP, AVIF, JPEG 2000, JPEG XL, SVG (read only) and WebAssembly JPEG and PNG codecs are available as plugins; see Formats and WEBP / WASM.

Edit the image

Image methods change the image in place and return it, so you can chain them:

index.ts
image.resize({ w: 400 }).greyscale().contrast(0.2);

Most methods take an options object, such as { w: 400 } for resize. Leave out h and the height follows the aspect ratio.

Because methods change the image, call clone when you want to keep the original or make several versions from one source:

index.ts
const thumbnail = image.clone().cover({ w: 150, h: 150 });

Try it here. Click a method to add it to the program, adjust its options, and watch the code panel build up the matching Jimp code. Upload your own image with the button at the top right.

Your first program
image.greyscale()Docs →

Remove all color, keeping the perceived brightness of each pixel.

This method has no options.

Loading Jimp…Drop an image to load it
PNG
index.js
import { Jimp } from "jimp"; const image = await Jimp.read("dice.png"); // Click a method above to add it here await image.write("output.png");

Browse every method on the methods page, grouped by what they do.

Save the image

write encodes the image and writes it to disk in Node.js. It picks the format from the file extension, so you can convert between formats by changing it:

index.ts
await image.write("output.png");
// JPEG with a quality from 0 to 100 (the default is 100)
await image.write("output.jpg", { quality: 80 });

To get the encoded bytes instead of a file, for example to send them in an HTTP response or show them in the browser, use getBuffer or getBase64 with a MIME type. The JimpMime export lists the MIME types of the built-in formats:

index.ts
import { Jimp, JimpMime } from "jimp";
const buffer = await image.getBuffer(JimpMime.png);
const dataUrl = await image.getBase64("image/jpeg", { quality: 60 });

Put it together

This program loads a photo, makes a square thumbnail and a captioned preview from it, and saves both. loadFont and the fonts in jimp/fonts are covered in Text and fonts.

thumbnails.ts
import { Jimp, HorizontalAlign, loadFont } from "jimp";
import { SANS_32_WHITE } from "jimp/fonts";
const image = await Jimp.read("dice.png");
// A 150 x 150 square, cropped from the center
const thumbnail = image.clone().cover({ w: 150, h: 150 });
await thumbnail.write("dice-thumb.png");
// A smaller, grey preview with a caption
const font = await loadFont(SANS_32_WHITE);
image
.resize({ w: 400 })
.greyscale()
.print({
font,
x: 0,
y: 10,
text: { text: "Dice", alignmentX: HorizontalAlign.CENTER },
maxWidth: image.width,
});
await image.write("dice-preview.jpg", { quality: 80 });

Handle errors

Loading, decoding and encoding are asynchronous, so errors arrive as rejected promises. Wrap them in try/catch:

index.js
try {
const image = await Jimp.read("photos/missing.png");
} catch (error) {
console.error(error.message);
// ENOENT: no such file or directory, open 'photos/missing.png'
}

The errors you’re most likely to see first:

Message Cause
ENOENT: no such file or directory, open '<path>' In Node.js, the file doesn’t exist.
Could not load Buffer from URL: <url> The URL couldn’t be fetched, for example because of a network or CORS error.
HTTP Status 404 for url <url> The URL was fetched, but the server returned an error status.
Could not find MIME for Buffer The data isn’t an image Jimp recognizes.
Mime type image/webp does not support decoding The image is in a format Jimp doesn’t include by default. Add a format plugin.
Unsupported MIME type: image/webp You asked write or getBuffer for a format that isn’t installed.
Cannot write "<path>": the path has no recognisable file extension … write couldn’t tell the format from the path. Add an extension such as .png.

Image methods are synchronous and throw straight away when an option is wrong. Options objects are validated with zod, so a bad option throws a ZodError whose issues say which option failed:

index.js
try {
image.resize({ w: -5 });
} catch (error) {
console.error(error.issues[0].message);
// Too small: expected number to be >=0
}

Errors and validation covers these in more detail.

Next steps