npmsharpv0.34.5
npmIntermediate

sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images

image-processingresizewebpaviflibvipsjpegpngtiffgifsvg
The Problem

Node.js image processing was historically slow and memory-hungry โ€” libraries used ImageMagick via child processes, paying the cost of spawning a new process for every image. Sharp wraps libvips, a C library that processes images in a streaming pipeline, using far less memory and running much faster.

Mental Model

Sharp is a transformation pipeline for images. You chain operations: sharp(input).resize(800, 600).webp({ quality: 80 }).toFile(output). The pipeline is lazy โ€” nothing runs until you call a finaliser like .toFile() or .toBuffer(). libvips processes the image in a streaming pass rather than loading it fully into memory.

60-second start

Install sharp

npm install sharp
import { } from 'sharp';

Use it when

Use Sharp for image resizing, format conversion (JPEG to WebP/AVIF), thumbnail generation, watermarking, and metadata extraction in Node.js. It's the standard choice for image processing in server-side Next.js, image CDN backends, and upload pipelines.

Skip it when

Sharp is a native module โ€” it requires native binaries and can complicate deployment in serverless environments. For Cloudflare Workers or edge functions, use the Cloudflare Images API or Vercel's built-in image optimisation instead.

Alternatives
jimpPure JavaScript image processing โ€” no native binaries, easier to deploy, but 10-20x slower than Sharp
canvasNode Canvas API for arbitrary 2D drawing โ€” better when you need to compose images with text and shapes
imagemagickBroader format support and filters via CLI โ€” use it for edge cases Sharp doesn't cover

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.