{"id":11144,"library":"jimp","title":"Jimp (JavaScript Image Manipulation Program)","description":"Jimp is a comprehensive image processing library for Node.js, written entirely in JavaScript with zero native dependencies. It enables various image manipulation tasks such as resizing, cropping, color adjustments, and format conversions without external binaries. The current stable version is 1.6.1, reflecting an active development and release cadence with multiple patch and minor versions in recent months. Key differentiators include its pure JavaScript implementation, which ensures high portability across diverse environments, and a modular plugin architecture for customized builds. Jimp supports a wide range of formats, including JPEG, PNG, BMP, TIFF, and GIF, making it a versatile choice for server-side image processing workflows.","status":"active","version":"1.6.1","language":"javascript","source_language":"en","source_url":"https://github.com/jimp-dev/jimp","tags":["javascript","image","image processing","image manipulation","png","jpg","jpeg","bmp","resize","typescript"],"install":[{"cmd":"npm install jimp","lang":"bash","label":"npm"},{"cmd":"yarn add jimp","lang":"bash","label":"yarn"},{"cmd":"pnpm add jimp","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` works, ESM `import` is preferred in modern Node.js environments (>=18). The Jimp class is a named export.","wrong":"const Jimp = require('jimp');","symbol":"Jimp","correct":"import { Jimp } from 'jimp';"},{"note":"For browser-specific builds or older bundlers, explicitly importing from `jimp/browser` was common. As of v1.1.4, bundler integration improved, allowing `import { Jimp } from 'jimp'` to often work correctly in browser contexts too, but `jimp/browser` remains an option for direct default imports.","wrong":"import Jimp from 'jimp';","symbol":"Jimp (default)","correct":"import Jimp from 'jimp/browser';"},{"note":"Jimp.read is a static method of the named `Jimp` class. Ensure you use the named import for `Jimp`.","wrong":"import Jimp from 'jimp';\nconst image = await Jimp.read('path/to/image.png');","symbol":"Jimp.read","correct":"import { Jimp } from 'jimp';\nconst image = await Jimp.read('path/to/image.png');"},{"note":"For advanced TypeScript usage, you might import specific types from the `@jimp/types` package, although `Jimp` itself ships with types.","symbol":"JimpType","correct":"import type { JimpType } from '@jimp/types';"}],"quickstart":{"code":"import { Jimp } from 'jimp';\nimport path from 'path';\nimport fs from 'fs/promises';\n\nasync function processImage() {\n  const inputPath = path.resolve('./input.png');\n  const outputPath = path.resolve('./output-processed.jpg');\n  const fontPath = path.resolve(__dirname, '../../node_modules/@jimp/plugin-print/fonts/open-sans/open-sans-16-black/open-sans-16-black.fnt'); // Example font path\n\n  try {\n    // Ensure input.png exists for demonstration\n    // For a real app, you'd fetch or use an existing file\n    // await fs.writeFile(inputPath, Buffer.from('...', 'base64')); // Example: write a placeholder image\n\n    const image = await Jimp.read(inputPath); // Read the image\n    \n    // Resize, grayscale, and add text\n    const font = await Jimp.loadFont(fontPath);\n    \n    image\n      .resize(300, Jimp.AUTO) // resize to 300px width, auto height\n      .quality(80) // set JPEG quality\n      .greyscale() // set greyscale\n      .print(font, 10, 10, 'Hello Jimp!') // add text\n      .write(outputPath); // save\n\n    console.log(`Image processed and saved to ${outputPath}`);\n  } catch (error) {\n    console.error('Error processing image:', error);\n  }\n}\n\n// Create a dummy input.png for the quickstart if it doesn't exist\nasync function createDummyImage() {\n  const dummyImagePath = path.resolve('./input.png');\n  if (!await fs.stat(dummyImagePath).catch(() => false)) {\n    const dummyImage = await new Jimp(100, 100, 0xFF0000FF); // 100x100 red image\n    await dummyImage.write(dummyImagePath);\n    console.log(`Created dummy image at ${dummyImagePath} for quickstart.`);\n  }\n}\n\ncreateDummyImage().then(() => processImage());","lang":"typescript","description":"This quickstart demonstrates how to read an image, perform common manipulations like resizing, converting to grayscale, adding text, and saving the output to a new file. It includes basic error handling and uses modern ESM syntax."},"warnings":[{"fix":"Initialize Jimp with desired plugins: `import Jimp from 'jimp/browser'; import { blur } from '@jimp/plugin-blur'; const customJimp = Jimp.extend(blur); await customJimp.read(...)` or `import { Jimp } from 'jimp'; Jimp.extend(blur);`","message":"Starting from `v1.2.0`, most plugins (e.g., blur, color, print) are no longer included by default with the main `jimp` package. To use these functionalities, you must explicitly import and add them to a custom Jimp instance.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Review existing code using `brightness` and adjust the numeric argument (e.g., a previous `0.5` might now be `1.5` for similar brightening, or `0.5` for dimming).","message":"The `brightness` function behavior changed in `v1.1.2` to align with standard CSS brightness implementations. Previously, it used an inverted multiplication. A value of `1` now means no change, with values above `1` increasing brightness.","severity":"breaking","affected_versions":">=1.1.2"},{"fix":"For new projects, prefer `import { Jimp } from 'jimp';` and rely on modern bundlers to pick up the correct export. If issues persist in a browser context, consider `import Jimp from 'jimp/browser';` or refer to your bundler's configuration.","message":"Older versions of Jimp (before `v1.1.4`) often required importing from `jimp/browser` specifically for browser environments to ensure correct bundler integration. While improved, some older configurations might still encounter issues.","severity":"gotcha","affected_versions":"<1.1.4"},{"fix":"Always use `import { Jimp } from 'jimp';` and `await` for asynchronous operations like `Jimp.read` and `image.write`.","message":"When working with `jimp` in ESM projects (e.g., Node.js with `\"type\": \"module\"` or bundlers), ensure you use `import` statements. Attempting to use `require()` might lead to errors about `require is not defined`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { Jimp } = require('jimp');` to `import { Jimp } from 'jimp';`.","cause":"Attempting to use `require()` in an ES Module context (e.g., in a `type: \"module\"` project) for a package that is primarily ESM or has a main ESM export.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... Not supported"},{"fix":"Ensure you are using the named import: `import { Jimp } from 'jimp';`.","cause":"Incorrect import of the Jimp class, often caused by using a default import (`import Jimp from 'jimp'`) when `Jimp` is a named export, or trying to access a static method on an incorrectly imported object.","error":"TypeError: Jimp.read is not a function"},{"fix":"Always `await` asynchronous Jimp operations, especially `Jimp.read()`: `const image = await Jimp.read('path/to/image.png');`","cause":"Attempting to call `.write()` or other manipulation methods on an image object that has not been `await`ed, or if `Jimp.read` failed to return an image.","error":"TypeError: Cannot read properties of undefined (reading 'write')"}],"ecosystem":"npm"}