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 >= 20.9.0、Deno 和 Bun。
🌐 It can be used with all JavaScript runtimes that provide support for Node-API v9, including Node.js >= 20.9.0, Deno and Bun.
调整图片大小通常比使用最快的 ImageMagick 和 GraphicsMagick 设置快 4 到 5 倍,因为它使用了 libvips。
🌐 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.
可以生成 Deep Zoom 图片金字塔,适合用于像 OpenSeadragon 这样的“滑动地图”切片查看器。
🌐 Deep Zoom image pyramids can be generated, suitable for use with “slippy map” tile viewers like OpenSeadragon.
🌐 Fast
这个模块由极快的 libvips 图片处理库驱动,该库最初于1989年在伯贝克学院创建,目前由由 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 输出图片时,Huffman 表会被优化,而无需使用像 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.