sharp
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@img/sharp-darwin-arm64 | 0.33.2 | 97.91 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-darwin-x64 | 0.33.2 | 102.5 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-libvips-darwin-arm64 | 1.0.1 | 6.69 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-darwin-x64 | 1.0.1 | 7.51 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linux-arm64 | 1.0.1 | 6.74 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linux-arm | 1.0.1 | 5.91 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linux-s390x | 1.0.1 | 6.09 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linux-x64 | 1.0.1 | 6.72 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linuxmusl-arm64 | 1.0.1 | 6.76 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-libvips-linuxmusl-x64 | 1.0.1 | 6.85 MB | LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-linux-arm64 | 0.33.2 | 102.45 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-linux-arm | 0.33.2 | 98.29 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-linux-s390x | 0.33.2 | 110.23 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-linux-x64 | 0.33.2 | 110.28 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-linuxmusl-arm64 | 0.33.2 | 107.29 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-linuxmusl-x64 | 0.33.2 | 113.97 kB | Apache-2.0 | prod optional | 1 |
@img/sharp-wasm32 | 0.33.2 | 3.45 MB | Apache-2.0 AND LGPL-3.0-or-later AND MIT | prod optional | 1 |
@img/sharp-win32-ia32 | 0.33.2 | 7.71 MB | Apache-2.0 AND LGPL-3.0-or-later | prod optional | 1 |
@img/sharp-win32-x64 | 0.33.2 | 7.77 MB | Apache-2.0 AND LGPL-3.0-or-later | prod optional | 1 |
color | 4.2.3 | 5.64 kB | MIT | prod | |
detect-libc | 2.0.3 | 23.07 kB | Apache-2.0 | prod | |
semver | 7.6.2 | 93.19 kB | ISC | prod |
Sharp is a high-performance Node.js module used for image processing. It is the fastest tool to resize images, especially JPEG, PNG, WebP, GIF, AVIF, and TIFF formats. The typical use case is to convert large images to smaller, web-friendly ones with varying dimensions. Apart from resizing, it offers operations like rotation, extraction, compositing, and gamma correction. Sharp is faster than using quickest ImageMagick and GraphicsMagick settings due to its use of libvips.
Sharp is easy to use with Node.js. First, install it using npm with the command npm install sharp
. Once installed, require it in your JavaScript file like const sharp = require('sharp')
. You can then use it to resize, rotate or change image setting.
Here are some usage examples: Callback method:
const sharp = require('sharp');
sharp(inputBuffer)
.resize(320, 240)
.toFile('output.webp', (err, info) => { ... });
Promise method:
const sharp = require('sharp');
sharp('input.jpg')
.rotate()
.resize(200)
.jpeg({ mozjpeg: true })
.toBuffer()
.then( data => { ... })
.catch( err => { ... });
Async/await method:
const sharp = require('sharp');
const semiTransparentRedPng = await sharp({
create: {
width: 48,
height: 48,
channels: 4,
background: { r: 255, g: 0, b: 0, alpha: 0.5 }
}
})
.png()
.toBuffer();
Stream method:
const sharp = require('sharp');
const roundedCorners = Buffer.from(
'<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
);
const roundedCornerResizer =
sharp()
.resize(200, 200)
.composite([{
input: roundedCorners,
blend: 'dest-in'
}])
.png();
readableStream
.pipe(roundedCornerResizer)
.pipe(writableStream);
You can find the complete documentation for sharp at sharp.pixelplumbing.com. The documentation provides complete installation instructions, API documentation, benchmark tests, and a changelog.