jimp@1 The JavaScript Image Manipulation Program

Load.Stack.Save.

Jimp reads, edits and writes images in plain JavaScript: Node, the browser, workers, anywhere JavaScript runs, with no native dependencies. Every edit is a method call like .blur(4). In Jimp Studio, every method call is a layer.

$pnpm add jimp
Hover to explode the stack · each plane is rendered live by Jimp

What's in the box

▸ Formats
Image FormatsSupported image formats include PNG, JPEG, BMP, GIF, and TIFF.
▸ Adjustments
Image ManipulationYou can resize, crop, apply filters and more.
▸ Plug-ins
PluggableCreate your own plugins to add new image manipulation methods or formats.
▸ Runtime
Just JavaScriptJimp is just JavaScript, so you can use it anywhere that JavaScript can be used.

Usage

Using Jimp is simple. Load an image, manipulate it, and save it.

1

Load an image.

import { Jimp } from "jimp";

const image = await Jimp.read("test/image.png");
2

Manipulate the image.

image.resize({ w: 100 });
3

Save the image.

await image.write("test/output.png");
Getting StartedInstall Jimp and learn the load → edit → save loop.
→
API ReferenceThe Jimp class and every filter, with live before/after previews.
→
Jimp is MIT licensed and built by its contributors. Jimp Studio is a docs prototype, not a real product, and it ships no third-party UI assets.
Jimp output
✕The Layers palette is the method chain. Toggle an eye to comment a call out, drag layers to reorder them, or add one with ◐ Adjustment. The code in the Actions palette updates as you go.
Drop image → Jimp.fromBuffer()
Jclass Jimp

API Reference

Everything hangs off one class. Read an image into a Jimp instance, call methods on it (each plugin adds some), then export it. Methods that change pixels return the image, so they chain.

MemberWhat it does
Jimp.read(url | path, options?)Load an image from a URL, a file path, or a Buffer. Resolves to a Jimp instance. Decode options are keyed by MIME type; see Reading Large Images.
Jimp.fromBuffer(buffer)Decode an ArrayBuffer or Buffer. This is how File › Open works in this app.
Jimp.fromBitmap(imageData)Wrap raw RGBA pixels, such as a canvas ImageData.
new Jimp({ width, height, color })Create a blank image.
image.clone()Copy the image. The playground clones the source before replaying the layers.
image.getPixelColor(x, y)Read one pixel as an RGBA integer. Try the Eyedropper tool (I).
image.getBase64(mime)Encode to a data URL. Async in v1.
image.getBuffer(mime, options?)Encode to a Buffer. Async in v1.
image.write(path, options?)Encode and save (Node). Async in v1.
◐Filter Gallery: every thumbnail below was rendered by Jimp in this tab

Drag across a thumbnail to compare before and after. Add layer puts the method on top of the stack in the Playground.

docs / guides / getting-started.mdx

Getting Started

How to use Jimp

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.

Read the full documentation to learn more about the API.

pnpm add jimp

Jimp supports the following image formats:

Watch out!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.

Usage

The workflow for using jimp:

  1. Load an image.

    import { Jimp } from "jimp";
    
    const image = await Jimp.read("test/image.png");
  2. Manipulate the image. Click ▶ Open as layers to load the snippet into the Playground and keep editing.

    image.resize({ w: 100 });
  3. Save the image.

    await image.write("test/output.png");

Chaining

Manipulation methods return the image, so you can chain them. Each call runs in order on the result of the one before. That's how the Playground works: the Layers palette is a chain read from the bottom up.

image
  .resize({ w: 400 })
  .greyscale()
  .contrast(0.4)
  .posterize(4);
docs / guides / browser.mdx

Using in Browser

How to use Jimp in the browser.

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 instead.

Usage

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. This page does exactly that.

<script type="module">
  import { Jimp } from "https://cdn.jsdelivr.net/npm/jimp@1/dist/browser/index.js";

  const image = await Jimp.read("/some/url");

  image.greyscale();

  document.querySelector("img").src = await image.getBase64("image/png");
</script>

The same file is on unpkg at https://unpkg.com/jimp@1/dist/browser/index.js. jimp@1 always loads the latest v1 release. Pin an exact version such as jimp@1.7.0 to make sure an update never changes your page.

The jimp/fonts export isn't self-contained, so it can't be imported from a CDN. Load your fonts by URL with loadFont instead.

With hosted file

You can initialize a Jimp instance from a URL or a file path.

import { Jimp } from "jimp";

// Read a file hosted on the same domain
const image1 = await Jimp.read("/some/url");

// Read a file hosted on a different domain
const image2 = await Jimp.read("https://some.other.domain/some/url");

With uploaded files

Or you can use Jimp with an ArrayBuffer. Here we take a user's uploaded image and modify it to greyscale. In this app, File › Open Image… (or dropping a file on the canvas) does the same thing.

function handleFile(e) {
  const reader = new FileReader();

  reader.onload = async (e) => {
    const image = await Jimp.fromBuffer(e.target?.result);

    image.greyscale();

    const base64 = await image.getBase64("image/jpeg");
  };

  reader.readAsArrayBuffer(e.target.files[0]);
}

input.addEventListener("change", handleFile);

Using Canvas

You can also use Jimp with a canvas.

const canvas = document.getElementById("my-canvas");
const ctx = canvas.getContext("2d");

// Load the canvas into a Jimp instance
const image = await Jimp.fromBitmap(
  ctx.getImageData(0, 0, canvas.width, canvas.height)
);

// Manipulate the image
image.greyscale();

const imageData = new ImageData(
  new Uint8ClampedArray(image.bitmap.data),
  image.bitmap.width,
  image.bitmap.height
);

// Write back to the canvas
ctx.putImageData(imageData, 0, 0);

Web Workers

Jimp can be slow and you don't want that running on the main thread. Workers can make this experience a lot better. First define a worker. This is where you should import jimp and do your image transformations.

import { Jimp } from "jimp";

self.addEventListener("message", async (e) => {
  const image = await Jimp.fromBuffer(e.data.image);

  if (e.data.options.blur) {
    image.blur(e.data.options.blur);
  }

  self.postMessage({ base64: await image.getBase64("image/png") });
});
docs / guides / reading-large-images.mdx

Reading Large Images

How to pass decode options to Jimp, including the size limits for each format.

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 to Jimp.read and Jimp.fromBuffer 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.

import { Jimp } from "jimp";

const image = await Jimp.read("huge-photo.jpg", {
  "image/jpeg": { maxResolutionInMP: 200, maxMemoryUsageInMB: 1024 },
  "image/gif": { maxResolutionInMP: 200 },
  "image/tiff": { maxResolutionInMP: 200 },
  "image/bmp": { maxResolutionInMP: 200 },
});

When an image is over a limit, decoding throws an error instead of allocating memory for it.

Options by format

Resolution limits are in megapixels (width × height ÷ 1,000,000). A 100 megapixel limit allows a 10,000 × 10,000 image.

JPEG (image/jpeg)

OptionDefaultDescription
maxResolutionInMP100Largest image, in megapixels, that will be decoded.
maxMemoryUsageInMB512Largest amount of memory, in megabytes, the decoder may allocate.
tolerantDecodingtrueDecode corrupt or truncated files as far as possible instead of throwing.
colorTransformautoWhether to convert from YCbCr to RGB. By default this is chosen from the image's color model.

A large JPEG can hit maxMemoryUsageInMB before maxResolutionInMP, so raise both when needed.

GIF, TIFF and BMP

Each takes maxResolutionInMP (default 100). GIF checks every frame and TIFF checks every tile.

PNG (image/png)

PNG has no size limit. It takes checkCRC (default true), which throws if a chunk's checksum doesn't match.

docs / guides / exif.mdx

EXIF

How Jimp reads, rotates and writes EXIF metadata.

Cameras and phones store metadata in JPEG files as EXIF: the camera make and model, the resolution (DPI), the date, the orientation and often the GPS location. Jimp reads EXIF from JPEG images. Other formats are read without it.

Auto-rotation on read

Cameras often store the pixels sideways and record how to turn them in the EXIF Orientation tag. When Jimp.read or Jimp.fromBuffer 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.

import { Jimp } from "jimp";

// Stored as 3000x4000 with orientation 6 (rotate 90° clockwise)
const image = await Jimp.read("photo.jpg");

image.width; // 4000
image.height; // 3000

Reading EXIF data

The parsed EXIF is on image._exif, in the format exif-parser returns. It isn't part of Jimp's typed API, so TypeScript needs a cast.

const image = await Jimp.read("photo.jpg");
const { tags } = (image as any)._exif;

tags.Make; // "Canon"
tags.Orientation; // 1, as the pixels were rotated

Writing EXIF data

By default Jimp writes no EXIF. To keep the metadata of a JPEG you read, pass exif: true when writing a JPEG:

const image = await Jimp.read("photo.jpg");

image.resize({ w: 800 });

await image.write("small.jpg", { quality: 90, exif: true });
GPS goes along for the rideEverything else, including maker notes and GPS location, is copied unchanged. Leave the option off when publishing images whose location shouldn't be shared.
docs / guides / writing-plugins.mdx

Writing Plugins

How to write plugins for Jimp

There are two types of plugins you can write for Jimp:

  1. Image format plugins
  2. Image manipulation plugins

You can combine plugins to create a Custom Jimp.

Image format plugins

Image format plugins are responsible for loading and saving images in a specific format. An image format plugin is composed of two functions: encode and decode.

import { Format } from "@jimp/types";
import WEBP, { WEBPOptions } from "webp-js";

export default function webp() {
  return {
    mime: "image/webp",
    // Encode the bitmap as a WEBP image
    encode: (bitmap, options: WEBPOptions = {}) =>
      WEBP.encode(bitmap, quality).data,
    // Decode a WEBP image into a bitmap
    decode: (data) => WEBP.decode(data),
  } satisfies Format<"image/webp">;
}

Image manipulation plugins

An image manipulation method takes an image as its first argument, does something to it, and returns the image. Every layer in the Playground is one of these.

import { JimpClass } from "@jimp/types";

export const methods = {
  blur<I extends JimpClass>(image: I, r: number) {
    // Implementation
    return image;
  },
};

Generally our method APIs follow this pattern:

  • They can take 1 primitive as an option (other than image)
  • Otherwise they take an options object defined and validated by zod.
docs / guides / custom-jimp.mdx

Custom Jimp

How to create a custom Jimp

If you don't want to use all the default plugins included in the jimp package, you can create a custom Jimp with createJimp from @jimp/core.

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");

Using a custom Jimp outside of Node.js

Jimp's packages import Buffer from the buffer package instead of relying on the Node.js global, so a custom Jimp works in browsers and in Cloudflare Workers without a Buffer polyfill.

The jimp package ships a pre-bundled browser build with everything it needs. A custom Jimp is bundled by your own bundler instead. If you see ReferenceError: Buffer is not defined, update your Jimp packages.

docs / guides / migrate-to-v1.mdx

Migrating to v1

How to migrate from v0 to v1

The goals of v1 were to:

  1. Make jimp easier to use in any environment
  2. Make jimp's API more consistent and easier to use
  3. Replace many constants with string values powered by TS

Async/Sync

In v1 all "export" methods are async. They have also been renamed: getBufferAsync → getBuffer, getBase64Async → getBase64, writeAsync → write. Callbacks are no longer supported.

// v0
Jimp.read("image.png", (err, image) => {
  if (err) throw err;
  image.write("output.png");
});

// v1
const image = await Jimp.read("image.png");
await image.write("output.png");

Importing

Jimp no longer uses a default export. Instead it uses named exports.

import { Jimp } from "jimp";

Positional Arguments to Options Objects

In v0 most methods used positional arguments, which leads to code that's harder to read and extend. Now they take options objects:

// v0
image.resize(100, 100);
// v1
image.resize({ w: 100, h: 100 });
docs / guides / webp.mdx

Using WEBP (and other WASM plugins)

How to use Jimp WebP and other WASM plugins.

The default build of Jimp only includes image formats written in JavaScript. To use WEBP (and anything else we don't have a JS implementation for) you need format plugins and a custom Jimp. The WASM plugins aren't dependencies of jimp, so install the ones you need alongside @jimp/core:

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,
});

Browser Usage

Since you're no longer using a pre-bundled version of jimp, your bundler has to handle the code written for Node. Vite 7 and earlier need some config for the WASM plugins, because the @jsquash codecs load their WASM relative to their own files.

No documents open. Pick one in the File Browser, or press ⌘O to open an image.
J
v7.0 · Layers Edition
Jimp StudioPRO
Professional JavaScript Image Manipulation · powered by jimp@1
Built on the Jimp contributors' open-source plugins.
Chain engineering: Background → … → top
Pixel pushing: 100% JavaScript, 0% native
Licensed to: You, reading the docs
Initializing…