Socket
Socket
Sign inDemoInstall

@jimp/plugin-resize

Package Overview
Dependencies
32
Maintainers
2
Versions
220
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jimp/plugin-resize

Resize an image.


Version published
Weekly downloads
929K
decreased by-17%
Maintainers
2
Install size
265 kB
Created
Weekly downloads
 

Readme

Source

@jimp/plugin-resize

Resize an image.

Resizes the image to a set width and height using a 2-pass bilinear algorithm/

Usage

  • @param {number} w the width to resize the image to (or Jimp.AUTO)
  • @param {number} h the height to resize the image to (or Jimp.AUTO)
  • @param {string} mode (optional) a scaling method (e.g. Jimp.RESIZE_BEZIER)
  • @param {function(Error, Jimp)} cb (optional) a callback for when complete
import jimp from "jimp";

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

  // Resize the image to width 150 and auto height.
  await image.resize(150, jimp.AUTO);

  // Save and overwrite the image
  await image.writeAsync("test/image.png");
}

main();

Auto

Jimp.AUTO can be passes to either the height or width and jimp will scale the image accordingly. Jimp.AUTO cannot be both height and width.

// resize the height to 250 and scale the width accordingly
image.resize(Jimp.AUTO, 250);
// resize the width to 250 and scale the height accordingly
image.resize(250, Jimp.AUTO);

Resize modes

The default resizing algorithm uses a bilinear method.

Optionally, the following constants can be passed to choose a particular resizing algorithm:

Jimp.RESIZE_NEAREST_NEIGHBOR;
Jimp.RESIZE_BILINEAR;
Jimp.RESIZE_BICUBIC;
Jimp.RESIZE_HERMITE;
Jimp.RESIZE_BEZIER;
image.resize(250, 250, Jimp.RESIZE_BEZIER);

FAQs

Last updated on 23 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc