📂
File System5M+/wkApache-2.0

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
npm install sharp
yarn
yarn add sharp
pnpm
pnpm add sharp

Import

ESM
import sharp from 'sharp';

Quick Example

usage
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

Packagesharp
CategoryFile System
Weekly Downloads5M+
LicenseApache-2.0
Installnpm install sharp

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.