sharp

lovellApache-2.0活跃维护

基于 libvips 的高性能 Node.js 图像处理库,能快速完成 JPEG、PNG、WebP、AVIF、TIFF 的缩放裁剪与格式转换,适合服务端批量处理图片。

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

v0.35.5发布于 2026-09-27 13:44 UTC32,836star +7 / 7 天1,450fork同步于 2026-11-10 05:20 UTC

怎么上手

从 README 代码块原样提取,可能是其中一种安装方式
npm install sharp
硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本v0.35.5
  1. v0.35.5最新正式版2026-09-27 · 2026-09-27 13:44 UTC

    https://github.com/lovell/sharp-libvips/releases/tag/v1.3.4

    • Add upper bounds check on length of linear and GIF delay arrays.

    • Improve error handing when WebAssembly fallback also fails. #4593 @lazerg

    • TypeScript: Allow multi-frame options for JXL output. #4602 @ramin-010

    • TypeScript: Remove non-existent named export. #4604

    • Increase accepted dimensions when extending an image. #4605

    • Improve gain map support for extract and rotate operations. #4606

    • Tests: Ensure composite tests pass on big endian platforms. #4609

  2. v0.35.5-rc.1pre-release2026-09-27 · 2026-09-27 08:56 UTC
    查看更新说明

    https://github.com/lovell/sharp-libvips/releases/tag/v1.3.4-rc.1

    • Add upper bounds check on length of linear and GIF delay arrays.

    • Improve error handing when WebAssembly fallback also fails. #4593 @lazerg

    • TypeScript: Allow multi-frame options for JXL output. #4602 @ramin-010

    • TypeScript: Remove non-existent named export. #4604

    • Increase accepted dimensions when extending an image. #4605

    • Improve gain map support for extract operation. #4606

    • Tests: Ensure composite tests pass on big endian platforms. #4609

  3. v0.35.5-rc.0pre-release2026-09-22 · 2026-09-22 14:20 UTC
    查看更新说明

    https://github.com/lovell/sharp-libvips/releases/tag/v1.3.4-rc.0

    • Add upper bounds check on length of linear and GIF delay arrays.

    • Improve error handing when WebAssembly fallback also fails. #4593 @lazerg

    • TypeScript: Allow multi-frame options for JXL output. #4602 @ramin-010

    • TypeScript: Remove non-existent named export. #4604

    • Increase accepted dimensions when extending an image. #4605

    • Tests: Ensure composite tests pass on big endian platforms. #4609

  4. v0.35.42026-08-26 · 2026-08-26 09:38 UTC
    查看更新说明

    https://github.com/lovell/sharp-libvips/releases/tag/v1.3.3

    • Bound resize dimensions to coordinate limit.

    • Bound composite left and top to coordinate limit. #4564 @metsw24-max

    • Round palette bit depth up for png and gif colours. #4569 @metsw24-max

    • Ensure tiff.subifd input option is used. #4572 @metsw24-max

    • Ensure info.pages is correct when limiting input page range. #4578 @metsw24-max

    • Improve support for input Streams finishing before output is requested. #4584 @Jaybhade

  5. v0.35.4-rc.0pre-release2026-08-25 · 2026-08-25 23:00 UTC
    查看更新说明
    • Upgrade to libvips v8.18.6 for upstream bug fixes.

    • Bound resize dimensions to coordinate limit.

    • Bound composite left and top to coordinate limit. #4564 @metsw24-max

    • Round palette bit depth up for png and gif colours. #4569 @metsw24-max

    • Ensure tiff.subifd input option is used. #4572 @metsw24-max

    • Ensure info.pages is correct when limiting input page range. #4578 @metsw24-max

    • Improve support for input Streams finishing before output is requested. #4584 @Jaybhade

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    sharp

    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.