• Stars
    star
    27,645
  • Rank 655 (Top 0.02 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

sharp

sharp logo

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

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 running Node.js >= 14.15.0 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
const sharp = require('sharp');

Callback

sharp(inputBuffer)
  .resize(320, 240)
  .toFile('output.webp', (err, info) => { ... });

Promise

sharp('input.jpg')
  .rotate()
  .resize(200)
  .jpeg({ mozjpeg: true })
  .toBuffer()
  .then( data => { ... })
  .catch( err => { ... });

Async/await

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

Stream

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.

More Repositories

1

limax

Node.js module to generate URL slugs. Another one? This one cares about i18n and transliterates non-Latin scripts to conform to the RFC3986 standard. Mostly API-compatible with similar modules.
JavaScript
572
star
2

farmhash

Node.js implementation of FarmHash, Google's family of high performance hash functions
JavaScript
378
star
3

highwayhash

Node.js implementation of HighwayHash, Google's fast and strong hash function
JavaScript
210
star
4

sharp-libvips

Packaging scripts to prebuild libvips and its dependencies - you're probably looking for https://github.com/lovell/sharp
Shell
161
star
5

avif-cli

Command line utility to convert images to AVIF
JavaScript
139
star
6

hepburn

Node.js module for converting Japanese Hiragana and Katakana script to, and from, Romaji using Hepburn romanisation
JavaScript
124
star
7

64

High performance Base64 encoding and decoding for Node.js using SIMD (AVX2, AVX, SSE4.2, SSE4.1, SSSE3) acceleration
JavaScript
108
star
8

attention

No longer maintained - Node.js module to detect the dominant palette and salient region of an image
C++
56
star
9

detect-libc

Node.js module to detect details of the C standard library (libc) implementation provided by a given Linux system
JavaScript
55
star
10

icc

JavaScript module to parse International Color Consortium (ICC) profiles
JavaScript
54
star
11

shorter

Node.js module to very quickly (de)compress short strings. Uses the SIMD-powered entropy encoding features of shoco.
JavaScript
32
star
12

nginx-cache

Node.js module to find files in an Nginx cache based on partial URL keys
JavaScript
25
star
13

media-type

JavaScript module to parse and validate RFC6838 media types, anything from 'text/plain' to 'application/vnd.company.app.entity-v2+xml;charset=utf8'
JavaScript
15
star
14

libimagequant

libimagequant v2.4.1 fork (BSD-2-Clause) with support for building and cross-compiling via meson
C
11
star
15

uk-postcode

Node.js module for parsing and validating UK postcodes
JavaScript
11
star
16

cc

Code style linter for C++ source files used in Node.js native addons
JavaScript
10
star
17

cgif-packaging

Packaging scripts for cgif
Shell
8
star
18

package-libvips-darwin

Superseded by https://github.com/lovell/sharp-libvips
Ruby
5
star
19

deephouse.uk

Nunjucks
5
star
20

petra

Embed a caching, reverse HTTP proxy into an existing distributed ES6 web application
JavaScript
5
star
21

libvips-cpp-dll

DEPRECATED
JavaScript
2
star
22

aarch64-linux-musl-crosstools

Cross-compiler toolchain to produce linuxmusl-arm64v8 binaries on linuxmusl-x64
C++
2
star
23

rampart

Reverse HTTP proxy backed by distributed memory cache. Designed to protect APIs from intense GET request traffic spikes.
JavaScript
1
star
24

wi-scrapbook

Stoke Ferry WI Scrapbook 1965. Images are licensed under a Creative Commons BY-NC-SA 4.0 International License.
JavaScript
1
star
25

broad-norfolk

English to Broad Norfolk Translator
JavaScript
1
star
26

lovell.info

JavaScript
1
star
27

sharp-osx-ci

DEPRECATED
1
star
28

counted

Capture, store and track download_count values for assets distributed via Github Releases
JavaScript
1
star