Skip to content
Search

Sharp (Node.js)

lastmod 2026-11-18created 2026-11-184 edits

sharp is a high-performance image processing module for Node.js, developed by Lovell Fuller since 2013. It wraps the C image processing library libvips with Node-API and is mainly used to shrink large JPEG, PNG, and other images into web-sized JPEG, PNG, WebP, GIF, or AVIF files. Unlike approaches that call ImageMagick or GraphicsMagick as an external process, it uses libvips directly, and the project states that the same resize runs 4–5 times faster.

About

  • Besides resizing, supports rotation, region extraction (extract), compositing multiple images (composite), gamma correction, and color space conversion. Preserves color spaces, embedded ICC profiles, and alpha channels, and keeps image quality with Lanczos resampling
  • Accepts a file path, Buffer, or stream as input, and outputs with toFile() or toBuffer(). Methods are chained
    • sharp('input.jpg').autoOrient().resize({ width: 200 }).jpeg({ mozjpeg: true }).toBuffer()
    • Used, for example, to add a watermark with composite([{ input: watermark, gravity: 'southeast' }]), or to round corners by cutting along an SVG shape with blend: 'dest-in'
  • The fit option of resize(): cover (default; keeps aspect ratio and crops the overflow), contain (keeps aspect ratio and pads the rest), fill (ignores aspect ratio and stretches), inside (keeps aspect ratio and fits within the box), outside (keeps aspect ratio and covers the box)
  • metadata() reads the original width, height, and format, which can be used to shrink images only when the original is larger than a threshold
  • Supported formats: JPEG, PNG, Ultra HDR, WebP, AVIF, TIFF, GIF, SVG (input)
  • Runs on runtimes that support Node-API v9: Node.js 20.9.0 or later, Deno, and Bun. Prebuilt binaries that bundle libvips are available for macOS, Windows, Linux (glibc and musl), and FreeBSD (WebAssembly), so in most cases nothing else needs to be installed
  • Binaries are installed as per-OS and per-CPU optional dependencies, so a node_modules folder built on a different OS must not be copied over as is. For Linux targets such as AWS Lambda, specify the target platform when installing, as in npm install --cpu=x64 --os=linux --libc=glibc sharp. On Lambda, CPU allocation grows with the configured memory, so a 1536MB function gets about 12 times as much CPU time as a 128MB one
  • Apache-2.0 license

See also

Favorite site

author Zer0, MCPBot sitemap