sharp
Sharp is the highest-performance Node.js image processing library, using the libvips image processing library for fast, memory-efficient operations on JPEG, PNG…
Installation
npm install sharp
yarn add sharp
pnpm add sharp
Import
import sharp from 'sharp';
Quick Example
import sharp from 'sharp';
await sharp('photo.jpg')
.resize(800, 600, { fit: 'cover' })
.webp({ quality: 80 })
.toFile('photo-optimized.webp');
const metadata = await sharp('photo.jpg').metadata();
console.log(metadata.width, metadata.height, metadata.format);About sharp
Sharp is the highest-performance Node.js image processing library, using the libvips image processing library for fast, memory-efficient operations on JPEG, PNG, WebP, AVIF, TIFF, GIF, and SVG images. Sharp is typically 4-5x faster than ImageMagick and Jimp for common operations like resizing, cropping, and format conversion. The library processes images through a pipeline of operations: sharp('input.jpg').resize(300, 200).grayscale().toFormat('webp').toFile('output.webp'). Sharp supports resizing with various fit strategies (cover, contain, fill, inside, outside), cropping with attention or entropy-based smart crop, rotation, flipping, sharpening, blurring, composite operations (watermarking), color space conversion, and metadata extraction. The library handles ICC color profiles, EXIF data, and animated images (GIF, WebP). Sharp's streaming API processes images without loading the entire file into memory, essential for handling large images or high-throughput image processing services. The library works with both file paths and Buffers, supporting streaming from and to any Node.js readable/writable stream. Sharp is the standard image processing library for Node.js applications, used by image optimization services, CDNs, CMS platforms, and any backend that needs to process user-uploaded images.
Quick Facts
| Package | sharp |
| Category | File System |
| Weekly Downloads | 5M+ |
| License | Apache-2.0 |
| Install | npm install sharp |
Related Packages
Jimp (JavaScript Image Manipulation Program) is a pure JavaScript image processing library for Node.…
Multer is a Node.js middleware for handling multipart/form-data, which is primarily used for uploadi…
Formidable is a Node.js module for parsing form data, especially file uploads. Unlike Multer which i…
pdf-lib is a library for creating and modifying PDF documents in any JavaScript environment, working…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.