sharp高性能 Node.js 图像处理模块
sharp 是一个高性能的 Node.js 模块,典型用例是将常见格式的大图像转换为较小的、对网络友好的 JPEG、PNG、WebP 和不同尺寸的 AVIF 图像。由于使用了 libvips 库,调整图像大小的速度通常比使用 ImageMagick 和 GraphicsMagick 快 4 到 5 倍。
颜色空间、嵌入的 ICC 配置文件和 alpha 透明通道都得到了正确处理,Lanczos 重采样可确保不会因速度而牺牲质量。除了图像调整大小外,还可以进行旋转、提取、合成和伽马校正等操作。
大多数运行 Node.js >= 12.13.0 的 macOS、Windows 和 Linux 系统不需要任何额外的安装或运行时依赖项。
例子
npm install sharp
const sharp = require('sharp');
回调
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);
评论
MagickWandPHP图像处理模块
MagickWand是一个PHP的模块,用来访问ImageMagick的图像处理库。下面是一个使用MagicWand的代码片段:$magick_wand=NewMagickWand();MagickR
MagickWandPHP图像处理模块
0
mod_gfxApache图像处理模块
mod_gfx是一个对图像进行即时处理的Apache模块,安装方法:EnsureAPXS,libgd,andgccareinstalledCompilemodule(runmake)Copymodul
mod_gfxApache图像处理模块
0
libvips高性能的图像处理库
libvips是一个需求驱动的多线程图像处理库。与类似的库相比,libvips运行速度快,占用的内存很少。它有大约300个操作,包括算术,直方图,卷积,形态学操作,频率滤波,颜色,重采样,统计等。它支
libvips高性能的图像处理库
0