sharp README

The project's README from github.com/lovell/sharp. As one markdown file: README.md.

sharp

sharp logo

The typical use case for this high speed Node-API module is to convert large images in common formats to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.

It can be used with all JavaScript runtimes that provide support for Node-API v9, including Node.js (>= 20.9.0), Deno and Bun.

Resizing an image is typically 4x-5x faster than using the quickest ImageMagick and GraphicsMagick settings due to its use of libvips.

Colour spaces, embedded ICC profiles and alpha transparency channels are all handled correctly. Lanczos resampling ensures quality is not sacrificed for speed.

As well as image resizing, operations such as rotation, extraction, compositing and gamma correction are available.

Most modern macOS, Windows and Linux systems do not require any additional install or runtime dependencies.

Documentation

Visit sharp.pixelplumbing.com for complete installation instructions, API documentation, benchmark tests and changelog.

Examples

npm install sharp
// ESM
import sharp from 'sharp';

// CJS
const sharp = require('sharp');
await sharp(inputBuffer)
  .resize({ width: 320, height: 240 })
  .toFile('output.webp', (err, info) => { ... });
const output = await sharp('input.jpg')
  .autoOrient()
  .resize({ width: 200 })
  .jpeg({ mozjpeg: true })
  .toBuffer();
const semiTransparentRedPng = await sharp({
  create: {
    width: 48,
    height: 48,
    channels: 4,
    background: { r: 255, g: 0, b: 0, alpha: 0.5 }
  }
})
  .png()
  .toBuffer();
const roundedCorners = Buffer.from(
  '<svg><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'
);

const roundedCornerResizer =
  sharp()
    .resize(200, 200)
    .composite([{
      input: roundedCorners,
      blend: 'dest-in'
    }])
    .png();

readableStream
  .pipe(roundedCornerResizer)
  .pipe(writableStream);

Contributing

A guide for contributors covers reporting bugs, requesting features and submitting code changes.

Licensing

Copyright 2013 Lovell Fuller and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

sharp (lovell/sharp)

Searching Database…

32.8K ·GitHub
What is this?sharp is a high-performance image processing module for Node.js, built on the libvips library. Its typical job is converting large images in common formats into smaller, web-friendly files of varying dimensions.
Is this a library I call from my code, or a standalone app with an interface?It is a library, not an app: a Node-API module that you call from your own JavaScript code. There is no GUI or CLI — the resizing and conversions happen inside your program.
How do I add it to a project?Add it as a dependency with 'npm install sharp'. Full installation instructions and the API reference live at sharp.pixelplumbing.com.
Do I need to compile libvips or install anything else first?No manual libvips setup is needed: most modern macOS, Windows and Linux systems require no additional install or runtime dependencies.
Will it run on older versions of Node.js?No — it needs a runtime with Node-API v9 support: Node.js 20.9.0 or newer, or Deno and Bun. Older Node versions are not supported.
How fast is it compared to ImageMagick?Resizing is typically 4x-5x faster than the quickest ImageMagick and GraphicsMagick settings, thanks to its use of libvips.
Does that speed come at the cost of image quality?No — sharp uses Lanczos resampling, so quality is not sacrificed for speed, and colour spaces, embedded ICC profiles and alpha transparency channels are handled correctly.
Which image formats does it handle?JPEG, PNG, WebP, GIF and AVIF are named in the README, the repo description adds TIFF, and SVG appears among the GitHub topics.
Can I use sharp in commercial projects?Yes — it is licensed under the Apache License 2.0, a permissive license that allows commercial use, modification and redistribution.
Creator
lovell
Size
58.8 MB
Stars
32.8K
Age
13y
Commits · 90 Days