Skip to main content

sharp

高性能Node.js图片处理库。使用libvips最快速地调整JPEG、PNG、WebP、AVIF和TIFF图片大小。 Use when this capability is needed.

跳到安装

来源信息

仓库
tomevault-io/skills-registry
最近来源活动
2026年4月28日 22:53
检测到的 SKILL.md 语言
中文
星标
0
分支
0

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
2 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
sharp
description
高性能Node.js图片处理库。使用libvips最快速地调整JPEG、PNG、WebP、AVIF和TIFF图片大小。 Use when this capability is needed.
metadata
{"author":"aidotnet"}
# Sharp Tool ## Description High-performance image processing for resizing, converting, and manipulating images. ## Source - Repository: [lovell/sharp](https://github.com/lovell/sharp) - License: Apache-2.0 ## Installation ```bash npm install sharp ``` ## Usage Examples ### Resize Image ```typescript import sharp from 'sharp'; // Resize to specific dimensions await sharp('input.jpg') .resize(800, 600) .toFile('output.jpg'); // Resize with aspect ratio preserved await sharp('input.jpg') .resize(800, null) // Width 800, auto height .toFile('output.jpg'); // Resize with fit options await sharp('input.jpg') .resize(800, 600, { fit: 'cover', // cover, contain, fill, inside, outside position: 'center' // center, top, right, bottom, left }) .toFile('output.jpg'); ``` ### Convert Format ```typescript // Convert to WebP await sharp('input.jpg') .webp({ quality: 80 }) .toFile('output.webp'); // Convert to AVIF (modern format) await sharp('input.jpg') .avif({ quality: 60 }) .toFile('output.avif'); // Convert to PNG with transparency await sharp('input.jpg') .png({ compressionLevel: 9 }) .toFile('output.png'); ``` ### Image Manipulation ```typescript // Rotate and flip await sharp('input.jpg') .rotate(90) .flip() .toFile('output.jpg'); // Blur and sharpen await sharp('input.jpg') .blur(5) .sharpen() .toFile('output.jpg'); // Grayscale and tint await sharp('input.jpg') .grayscale() .tint({ r: 255, g: 128, b: 0 }) .toFile('output.jpg'); // Crop await sharp('input.jpg') .extract({ left: 100, top: 100, width: 500, height: 300 }) .toFile('output.jpg'); ``` ### Add Watermark ```typescript async function addWatermark(input: string, watermark: string, output: string) { const image = sharp(input); const { width, height } = await image.metadata(); // Resize watermark const watermarkBuffer = await sharp(watermark) .resize(Math.round(width! * 0.2)) .toBuffer(); await image .composite([{ input: watermarkBuffer, gravity: 'southeast', blend: 'over', }]) .toFile(output); } ``` ### Generate Thumbnails ```typescript async function generateThumbnails(input: string, sizes: number[]) { const image = sharp(input); await Promise.all(sizes.map(size => image .clone() .resize(size, size, { fit: 'cover' }) .jpeg({ quality: 80 }) .toFile(`thumb-${size}.jpg`) )); } // Usage await generateThumbnails('photo.jpg', [64, 128, 256, 512]); ``` ### Stream Processing ```typescript import { createReadStream, createWriteStream } from 'fs'; // Process large images with streams createReadStream('large-input.jpg') .pipe(sharp().resize(1920, 1080).jpeg({ quality: 85 })) .pipe(createWriteStream('output.jpg')); ``` ## Tags `image`, `resize`, `convert`, `thumbnail`, `processing` ## Compatibility - Codex: ✅ - Claude Code: ✅ --- > Converted and distributed by [TomeVault](https://tomevault.io/claim/aidotnet) — claim your Tome and manage your conversions. <!-- tomevault:4.0:skill_md:2026-04-11 -->
在 GitHub 查看