$ npm install @jimp/plugin-resize
Resize an image.
Resizes the image to a set width and height using a 2-pass bilinear algorithm/
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();
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);
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);
© 2010 - cnpmjs.org x YWFE | Home | YWFE