High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images
sharp is a high-performance image processing library for Node.js that leverages libvips, a low-level image processing library written in C. It's designed to handle the common need for transforming large images into smaller, web-optimized formats at production scale. With over 31 million weekly downloads, it's become the de facto standard for server-side image manipulation in the Node.js ecosystem.
The library was created to address performance bottlenecks in traditional image processing tools like ImageMagick and GraphicsMagick when used in Node.js environments. sharp is typically 4-5x faster than these alternatives because it operates directly on memory buffers and uses efficient multi-threaded processing via libvips. This performance advantage becomes critical when processing hundreds or thousands of images in web applications, serverless functions, or build pipelines.
sharp is used by developers building content management systems, e-commerce platforms, social media applications, and static site generators—anywhere images need to be resized, cropped, or optimized programmatically. It works with Node.js (v18.17.0+), Deno, and Bun, requiring no additional runtime dependencies on most modern systems. The library supports streaming operations, making it memory-efficient even when processing large image files.
The API is chainable and intuitive, supporting operations like resizing, cropping, rotation, format conversion, color manipulation, and compositing. It handles modern formats including AVIF and WebP alongside traditional JPEG, PNG, GIF, and TIFF. sharp also includes built-in optimizations from mozjpeg and pngquant, eliminating the need for separate optimization tools in your processing pipeline.
import sharp from 'sharp';
import { promises as fs } from 'fs';
// Resize and optimize an image for web delivery
await sharp('input.jpg')
.resize(800, 600, {
fit: 'cover',
position: 'center'
})
.jpeg({ quality: 85, mozjpeg: true })
.toFile('output.jpg');
// Create multiple thumbnail sizes from buffer
const imageBuffer = await fs.readFile('photo.png');
const sizes = [200, 400, 800];
await Promise.all(
sizes.map(size =>
sharp(imageBuffer)
.resize(size, size, { fit: 'inside' })
.webp({ quality: 80 })
.toFile(`thumbnail-${size}.webp`)
)
);
// Stream processing with metadata extraction
const metadata = await sharp('large-image.tiff').metadata();
console.log(`Original: ${metadata.width}x${metadata.height}`);
await sharp('large-image.tiff')
.rotate() // Auto-rotate based on EXIF
.resize(1920, 1080, { fit: 'inside', withoutEnlargement: true })
.png({ compressionLevel: 9 })
.toFile('optimized.png');
// Composite watermark onto image
await sharp('base-image.jpg')
.composite([{
input: 'watermark.png',
gravity: 'southeast'
}])
.toFile('watermarked.jpg');Thumbnail generation for user uploads: Automatically create multiple sizes of uploaded images (thumbnails, previews, full-size) for responsive web delivery. sharp can process uploads in memory as they arrive, generating all variants before storage.
Automated image optimization in build pipelines: Integrate into webpack, Vite, or Next.js builds to automatically compress and resize images during development or deployment, reducing bundle sizes and improving page load times.
Serverless image transformation APIs: Deploy sharp in AWS Lambda, Cloudflare Workers, or Vercel Functions to create on-demand image transformation services that resize or format images based on URL parameters.
Watermarking and compositing: Overlay logos, text, or watermarks onto images for content protection or branding. sharp's compositing features support alpha channels and multiple blend modes for professional results.
Deep Zoom image pyramid generation: Create tiled image pyramids for high-resolution image viewers like OpenSeadragon, enabling smooth zoom experiences for medical imaging, maps, or art galleries without loading entire massive files.
npm install sharppnpm add sharpbun add sharp