MCPcopy
hub / github.com/lovell/sharp

github.com/lovell/sharp @v0.35.3 sqlite

repository ↗ · DeepWiki ↗ · release v0.35.3 ↗
289 symbols 757 edges 99 files 161 documented · 56%
README

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.

Extension points exported contracts — how you extend this code

Sharp (Interface)
(no doc)
lib/index.d.ts
SharpOptions (Interface)
(no doc)
lib/index.d.ts
CacheOptions (Interface)
(no doc)
lib/index.d.ts
TimeoutOptions (Interface)
(no doc)
lib/index.d.ts
SharpCounters (Interface)
(no doc)
lib/index.d.ts

Core symbols most depended-on inside this repo

toBuffer
called by 644
lib/index.d.ts
resize
called by 497
lib/index.d.ts
metadata
called by 175
lib/index.d.ts
isInAcceptableRange
called by 132
test/unit/stats.js
isInRange
called by 111
test/unit/stats.js
isInteger
called by 108
test/unit/stats.js
toFile
called by 105
lib/index.d.ts
getPath
called by 99
test/fixtures/index.js

Shape

Function 153
Method 69
Interface 67

Languages

TypeScript100%

Modules by API surface

lib/index.d.ts136 symbols
lib/output.mjs35 symbols
lib/operation.mjs23 symbols
lib/libvips.mjs19 symbols
lib/is.mjs15 symbols
lib/colour.mjs9 symbols
lib/input.mjs8 symbols
test/unit/tile.js6 symbols
lib/utility.mjs6 symbols
lib/resize.mjs6 symbols
lib/channel.mjs5 symbols
test/unit/stats.js3 symbols

Dependencies from manifests, versioned

@astrojs/starlight0.41.0 · 1×
@biomejs/biome2.5.1 · 1×
@cpplint/cli0.1.0 · 1×
@emnapi/runtime1.11.1 · 1×
@img/colour1.1.0 · 1×
@img/sharp-libvips-dev1.3.2 · 1×
@img/sharp-libvips-dev-wasm321.3.2 · 1×
@img/sharp-libvips-win32-arm641.3.2 · 1×
@img/sharp-libvips-win32-ia321.3.2 · 1×
@img/sharp-libvips-win32-x641.3.2 · 1×
@img/sharp-wasm320.35.3 · 1×
@types/node* · 1×

For agents

$ claude mcp add sharp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact