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

# sharp

<picture><img src="https://sharp.pixelplumbing.com/sharp-logo.svg" width="160" height="160" alt="sharp logo" align="right"></picture>

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](https://github.com/libvips/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](https://sharp.pixelplumbing.com/) for complete
[installation instructions](https://sharp.pixelplumbing.com/install),
[API documentation](https://sharp.pixelplumbing.com/api-constructor),
[benchmark tests](https://sharp.pixelplumbing.com/performance) and
[changelog](https://sharp.pixelplumbing.com/changelog).

## Examples

```sh
npm install sharp
```

```javascript
// ESM
import sharp from 'sharp';

// CJS
const sharp = require('sharp');
```

```javascript
await sharp(inputBuffer)
  .resize({ width: 320, height: 240 })
  .toFile('output.webp', (err, info) => { ... });
```

```javascript
const output = await sharp('input.jpg')
  .autoOrient()
  .resize({ width: 200 })
  .jpeg({ mozjpeg: true })
  .toBuffer();
```

```javascript
const semiTransparentRedPng = await sharp({
  create: {
    width: 48,
    height: 48,
    channels: 4,
    background: { r: 255, g: 0, b: 0, alpha: 0.5 }
  }
})
  .png()
  .toBuffer();
```

```javascript
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](https://github.com/lovell/sharp/blob/main/.github/CONTRIBUTING.md)
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](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

(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)

rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*

nyc --reporter=lcov --branches=99 mocha --slow=1000 --timeout=60000 ./test/unit/*.js

license-checker --production --summary --onlyAllow="Apache-2.0;BSD;ISC;MIT"

documentation lint lib && node docs/build && node docs/search-index/build

cd docs && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp

jpeg png webp avif tiff gif svg jp2 dzi image resize thumbnail crop embed libvips vips

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

(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

semistandard && cc && npm run test-unit && npm run test-licensing && prebuild-ci

jpeg png webp tiff gif svg dzi image resize thumbnail crop embed libvips vips

semistandard && cc && nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js && prebuild-ci

rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*

for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done

jpeg png webp tiff gif svg dzi image resize thumbnail crop libvips vips

semistandard && cc && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js

semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js

rm -rf node_modules/ build/ include/ lib/ coverage/ test/fixtures/output.*

VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=30000 ./test/unit/*.js

node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=60000 ./test/unit/*.js

rm -rf coverage/ test/fixtures/output.* && npm install && npm test

High performance Node.js module to resize JPEG, PNG, WebP and TIFF images using the libvips library

jpeg png webp tiff dzi resize thumbnail crop libvips vips

node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js

VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=20000 ./test/unit/*.js

npm run clean && npm install && npm test

iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=30000 ./test/unit/*.js

cd test/leak; ./leak.sh; cd - > /dev/null

node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=20000 ./test/unit/*.js

iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=20000 ./test/unit/*.js

VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=15000 ./test/unit/*.js

node ./node_modules/mocha/bin/mocha --slow=5000 --timeout=15000 ./test/unit/*.js

iojs ./node_modules/mocha/bin/mocha --slow=5000 --timeout=15000 ./test/unit/*.js

VIPS_WARNING=0 node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- --slow=5000 --timeout=10000 ./test/unit/*.js

jpeg png webp tiff resize thumbnail crop libvips vips

jpeg png webp tiff gif resize thumbnail sharpen crop extract embed libvips vips stream

High performance Node.js module to resize JPEG, PNG and WebP images using the libvips library

jpeg png webp tiff gif resize thumbnail sharpen crop extract embed libvips vips fast buffer stream

jpeg png webp tiff gif resize thumbnail sharpen crop embed libvips vips fast buffer stream

High performance module to resize JPEG, PNG, WebP and TIFF images using the libvips image processing library

jpeg png webp tiff resize thumbnail sharpen crop embed libvips vips fast buffer

High performance module to resize JPEG and PNG images using the libvips image processing library

jpeg png resize thumbnail sharpen crop embed libvips fast buffer

jpeg png resize thumbnail sharpen crop embed libvips fast

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

jpeg png webp avif tiff gif svg dzi image resize thumbnail crop embed libvips vips

nyc --reporter=lcov --branches=99 mocha --parallel --slow=5000 --timeout=60000 ./test/unit/*.js

documentation lint lib && for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md --markdown-toc=false lib/$m.js >docs/api-$m.md; done && node docs/search-index/build

semistandard && cpplint && npm run test-unit && npm run test-licensing && node install/prebuild-ci

(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)

semistandard && cpplint && npm run test-unit && npm run test-licensing && prebuild-ci

High performance Node.js module to resize JPEG images using the libvips image processing library

jpeg resize thumbnail sharpen crop embed libvips fast

nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha --slow=1000 --timeout=20000 ./test/unit/*.js

nyc --reporter=lcov --reporter=text --check-coverage --branches=100 mocha --slow=1000 --timeout=30000 ./test/unit/*.js

npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types

node docs/build && node docs/search-index/build

rm -rf build/ .nyc_output/ coverage/ test/fixtures/output.*

license-checker --production --summary --onlyAllow="Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT"

rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*

cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp

npm run lint-cpp && npm run lint-js && npm run lint-types

rm -rf src/build/ test/fixtures/output.*

npm run lint-cpp && npm run lint-js && npm run lint-types && npm run lint-publish