🚀
高性能
使用 libvips 圖像處理庫,比 ImageMagick 和 GraphicsMagick 快 4-5 倍
Sharp 是 Node.js 中最快的圖像處理庫,專為現代 Web 應用設計。它使用 libvips 圖像處理庫,提供卓越的性能和內存效率。
import sharp from 'sharp';
// 調整圖像大小
await sharp('input.jpg')
.resize(300, 200)
.toFile('output.jpg');
// 轉換為 WebP 格式
await sharp('input.png')
.webp({ quality: 80 })
.toFile('output.webp');
// 創建縮略圖
await sharp('input.jpg')
.resize(100, 100, { fit: 'cover' })
.jpeg({ quality: 90 })
.toFile('thumbnail.jpg');npm install sharp或者使用 pnpm:
pnpm add sharp