talira

High performance Node.js image processing

open sourceApache-2.0self-hostablefree

sharp is a Node-API module that converts large images into smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF files, built on the libvips image library. It reads JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG, resizes with Lanczos resampling, and rotates, extracts, composites and corrects gamma while handling colour spaces, ICC profiles and alpha channels. The project says resizing is typically 4 to 5 times faster than the quickest ImageMagick and GraphicsMagick settings. Prebuilt binaries cover macOS, Linux and Windows on common architectures, it runs on Node.js, Deno and Bun, and an optional WebAssembly package covers other platforms.

Problems it solves

  • resize user-uploaded photos into thumbnails in my Node.js backend
  • convert JPEG and PNG uploads to WebP or AVIF to cut page weight
  • image resizing with ImageMagick is too slow and eats memory on our server
  • generate several sizes of an image for responsive srcset in a build step
  • resize images without shelling out to a command line tool from Node
  • strip or keep EXIF metadata and colour profiles when I process photos
  • compress PNGs and JPEGs further for the web with mozjpeg or pngquant settings
  • composite a watermark or overlay onto images on the server
  • rasterise an SVG to PNG in a serverless function
  • rotate phone photos the right way up based on their orientation
  • stream images through a resize pipeline without writing temp files
  • make Deep Zoom tiles for a pan-and-zoom image viewer

Features

  • reads JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG
  • writes JPEG, PNG, WebP, GIF, AVIF, TIFF and raw pixel data
  • resize with Lanczos resampling
  • rotate, extract, composite and gamma correction
  • colour spaces, ICC profiles and alpha channels
  • mozjpeg and pngquant optimisations
  • streams, Buffers and files, with one input feeding several pipelines
  • Deep Zoom image pyramids
  • prebuilt binaries with no extra runtime dependencies
  • runs on Node.js, Deno and Bun
View 1 more
  • optional WebAssembly package (@img/sharp-wasm32)

Limitations

  • Doesn't read or write HEIC (HEVC-compressed) images out of the box: that needs a globally installed libvips built with libheif, libde265 and x2651
  • Doesn't write JPEG 2000 or JPEG XL with its prebuilt binaries: both need a custom-built libvips1
  • Doesn't run in web browsers: its WebAssembly build needs a runtime with multi-threaded Wasm via Workers2

Capabilities

Has an APIplan not known

Alternatives

The same job

These do what sharp does.

  1. ImageMagick The open-source suite for image creation, conversion, and batch manipulation

Compare sharp with the top 3