Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsApr 24, 2026·3 min de lecture

Sharp — High-Performance Image Processing for Node.js

A high-speed Node.js module for resizing, converting, and transforming images using the libvips library.

assetLangBanner.body

Introduction

Sharp is the fastest Node.js module for resizing JPEG, PNG, WebP, AVIF, TIFF, GIF, and SVG images. It uses libvips under the hood, which processes images in streaming fashion with low memory usage, making it suitable for server-side image pipelines handling thousands of images.

What Sharp Does

  • Resizes images with multiple fit modes: cover, contain, fill, inside, outside
  • Converts between formats including JPEG, PNG, WebP, AVIF, TIFF, and raw pixel data
  • Applies operations like rotate, crop, flip, blur, sharpen, and composite
  • Extracts image metadata including dimensions, format, EXIF, and ICC profiles
  • Composites multiple images together with blend modes and positioning

Architecture Overview

Sharp wraps libvips, a demand-driven image processing library written in C. Instead of loading entire images into memory, libvips processes them in small tiles, keeping memory usage low even for large files. Sharp provides a fluent JavaScript API that builds an operation pipeline, which is executed in a native thread pool to avoid blocking the Node.js event loop.

Installation & Configuration

  • Install via npm; prebuilt libvips binaries download automatically for major platforms
  • Supports Linux, macOS, and Windows including ARM architectures and Lambda
  • Configure thread pool concurrency with sharp.concurrency() for server workloads
  • Disable cache with sharp.cache(false) in memory-constrained environments
  • Works with Buffer, Stream, and file path inputs and outputs

Key Features

  • 4-5x faster than ImageMagick and GraphicsMagick for common resize operations
  • Low memory footprint through streaming pixel processing
  • AVIF and animated WebP/GIF support for modern image formats
  • ICC color profile handling for accurate color space conversion
  • Pipeline API chains multiple operations in a single pass

Comparison with Similar Tools

  • Jimp — pure JavaScript so no native dependencies but significantly slower; Sharp uses native libvips
  • ImageMagick (via gm) — broader format support but slower and heavier; Sharp is faster for web-focused formats
  • Pillow (Python) — similar capability in Python; Sharp serves the Node.js ecosystem
  • Squoosh — browser-based with WASM codecs; Sharp runs server-side at higher throughput
  • libvips CLI — same engine but Sharp provides a Node.js-native API with streaming support

FAQ

Q: Does Sharp work in serverless environments like AWS Lambda? A: Yes. Sharp ships prebuilt binaries for Linux x64 and ARM64, and works in Lambda layers out of the box.

Q: Can Sharp handle animated GIFs? A: Yes. Sharp can read, resize, and convert animated GIFs and animated WebP images while preserving animation frames.

Q: How does Sharp handle EXIF orientation? A: By default Sharp auto-rotates images based on EXIF orientation data and strips the orientation tag from the output.

Q: Can I use Sharp with streams? A: Yes. Pass a readable stream as input and pipe the output to a writable stream for zero-copy processing.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires