sharp
这种高速 Node-API 模块的典型用例是将常见格式的大图片转换为较小的、网络友好的不同尺寸的 JPEG、PNG、WebP、GIF 和 AVIF 图片。
¥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.
它可与所有支持 Node-API v9 的 JavaScript 运行时一起使用,包括 Node.js >= 18.17.0、Deno 和 Bun。
¥It can be used with all JavaScript runtimes that provide support for Node-API v9, including Node.js >= 18.17.0, Deno and Bun.
由于使用了 libvips,调整图片大小通常比使用最快的 ImageMagick 和 GraphicsMagick 设置快 4 到 5 倍。
¥Resizing an image is typically 4x-5x faster than using the quickest ImageMagick and GraphicsMagick settings due to its use of libvips.
色彩空间、嵌入式 ICC 配置文件和 Alpha 透明度通道均已正确处理。Lanczos 重采样确保不会为了速度而牺牲质量。
¥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.
大多数现代 macOS、Windows 和 Linux 系统不需要任何额外的安装或运行时依赖。
¥Most modern macOS, Windows and Linux systems do not require any additional install or runtime dependencies.
npm install sharp
格式
¥Formats
该模块支持读取 JPEG、PNG、WebP、GIF、AVIF、TIFF 和 SVG 图片。
¥This module supports reading JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG images.
输出图片可以是 JPEG、PNG、WebP、GIF、AVIF 和 TIFF 格式以及未压缩的原始像素数据。
¥Output images can be in JPEG, PNG, WebP, GIF, AVIF and TIFF formats as well as uncompressed raw pixel data.
流、缓冲区对象和文件系统可用于输入和输出。
¥Streams, Buffer objects and the filesystem can be used for input and output.
单个输入流可以拆分为多个处理管道和输出流。
¥A single input Stream can be split into multiple processing pipelines and output Streams.
可以生成深度缩放图片金字塔,适合与 OpenSeadragon 等 “滑动映射” 平铺查看器一起使用。
¥Deep Zoom image pyramids can be generated, suitable for use with “slippy map” tile viewers like OpenSeadragon.
快速
¥Fast
该模块由速度极快的 libvips 图片处理库提供支持,该库最初于 1989 年在 Birkbeck 学院创建,目前由 John Cupitt 领导的一个小团队维护。
¥This module is powered by the blazingly fast libvips image processing library, originally created in 1989 at Birkbeck College and currently maintained by a small team led by John Cupitt.
一次仅保存一小部分未压缩图片数据并进行处理,充分利用多个 CPU 核心和 L1/L2/L3 缓存。
¥Only small regions of uncompressed image data are held in memory and processed at a time, taking full advantage of multiple CPU cores and L1/L2/L3 cache.
由于 libuv,一切都保持非阻塞,不会生成任何子进程,并且支持 Promises/async/await。
¥Everything remains non-blocking thanks to libuv, no child processes are spawned and Promises/async/await are supported.
优化
¥Optimal
mozjpeg
和 pngquant
的功能可分别用于优化 JPEG 和 PNG 图片的文件大小,而无需调用单独的 imagemin
进程。
¥The features of mozjpeg
and pngquant
can be used
to optimise the file size of JPEG and PNG images respectively,
without having to invoke separate imagemin
processes.
霍夫曼表在生成 JPEG 输出图片时进行了优化,而无需使用单独的命令行工具(如 jpegoptim 和 jpegtran)。
¥Huffman tables are optimised when generating JPEG output images without having to use separate command line tools like jpegoptim and jpegtran.
默认情况下禁用 PNG 过滤,这对于图表和线条艺术通常会产生与 pngcrush 相同的结果。
¥PNG filtering is disabled by default, which for diagrams and line art often produces the same result as pngcrush.
动画 GIF 输出的文件大小得到优化,无需使用单独的命令行工具(例如 gifsicle)。
¥The file size of animated GIF output is optimised without having to use separate command line tools such as gifsicle.
贡献
¥Contributing
贡献者指南 涵盖报告错误、请求功能和提交代码更改。
¥A guide for contributors covers reporting bugs, requesting features and submitting code changes.
许可
¥Licensing
版权所有 2013 Lovell Fuller 等。
¥Copyright 2013 Lovell Fuller and others.
根据 Apache 许可证 2.0 版(“许可”)获得许可;除非遵守许可证,否则你不得使用此文件。你可以在 https://www.apache.org/licenses/LICENSE-2.0 获取许可证副本
¥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.