Image Process Skill
This skill provides image processing capabilities including compression, background removal, background replacement, and upscaling.
Features
- - Image Compression: Compress images to reduce file size with adjustable quality
- Background Removal: AI-powered background removal using INLINECODE0
- Background Replacement: Replace background with a custom color or another image
- Image Upscaling: Enlarge images to bigger dimensions
Usage
1. Compress Image
CODEBLOCK0
2. Remove Background
CODEBLOCK1
3. Replace Background
CODEBLOCK2
4. Upscale Image
CODEBLOCK3
Parameters
compressImage
| Parameter | Type | Description |
|---|
| INLINECODE1 | string | Path to input image |
| INLINECODE2 |
number | Compression quality (1-100), default 80 |
|
output | string | Output file path |
removeBackground
| Parameter | Type | Description |
|---|
| INLINECODE4 | string/Buffer | Path or buffer of input image |
| INLINECODE5 |
string | Output file path (optional) |
replaceBackground
| Parameter | Type | Description |
|---|
| INLINECODE6 | string | Path to foreground image |
| INLINECODE7 |
string | Hex color (e.g. '#ffffff') or path to background image |
|
output | string | Output file path |
upscaleImage
| Parameter | Type | Description |
|---|
| INLINECODE9 | string | Path to input image |
| INLINECODE10 |
number | Scale factor (e.g. 2 for 2x), default 2 |
|
width | number | Target width (overrides scale) |
|
height | number | Target height (overrides scale) |
|
output | string | Output file path |
CLI Commands
CODEBLOCK4
Installation
CODEBLOCK5
Dependencies
- -
@imgly/background-removal-node - AI background removal - INLINECODE15 - High-performance image processing
图像处理技能
该技能提供图像处理能力,包括压缩、背景移除、背景替换和图像放大。
功能特性
- - 图像压缩:通过可调节质量参数压缩图像以减小文件大小
- 背景移除:使用@imgly/background-removal实现AI驱动的背景移除
- 背景替换:用自定义颜色或另一张图像替换背景
- 图像放大:将图像放大至更大尺寸
使用方法
1. 压缩图像
javascript
const { compressImage } = require(./index);
const result = await compressImage({
input: ./image.jpg,
quality: 80,
output: ./compressed.jpg
});
2. 移除背景
javascript
const { removeBackground } = require(./index);
const result = await removeBackground({
input: ./person.jpg,
output: ./person-nobg.png
});
3. 替换背景
javascript
const { replaceBackground } = require(./index);
// 替换为纯色
const result = await replaceBackground({
input: ./person.jpg,
background: #ffffff,
output: ./result.jpg
});
// 替换为另一张图像
const result = await replaceBackground({
input: ./person.jpg,
background: ./background.jpg,
output: ./result.jpg
});
4. 放大图像
javascript
const { upscaleImage } = require(./index);
// 按倍数缩放(2倍)
const result = await upscaleImage({
input: ./image.jpg,
scale: 2,
output: ./upscaled.jpg
});
// 或指定精确尺寸
const result = await upscaleImage({
input: ./image.jpg,
width: 2000,
height: 3000,
output: ./upscaled.jpg
});
参数说明
compressImage
| 参数 | 类型 | 描述 |
|---|
| input | string | 输入图像路径 |
| quality |
number | 压缩质量(1-100),默认80 |
| output | string | 输出文件路径 |
removeBackground
| 参数 | 类型 | 描述 |
|---|
| input | string/Buffer | 输入图像的路径或缓冲区 |
| output |
string | 输出文件路径(可选) |
replaceBackground
| 参数 | 类型 | 描述 |
|---|
| input | string | 前景图像路径 |
| background |
string | 十六进制颜色(如#ffffff)或背景图像路径 |
| output | string | 输出文件路径 |
upscaleImage
| 参数 | 类型 | 描述 |
|---|
| input | string | 输入图像路径 |
| scale |
number | 缩放倍数(如2表示2倍),默认2 |
| width | number | 目标宽度(覆盖scale参数) |
| height | number | 目标高度(覆盖scale参数) |
| output | string | 输出文件路径 |
CLI命令
bash
压缩
image-process compress ./photo.jpg -q 80
移除背景
image-process remove-bg ./person.jpg
替换背景
image-process replace-bg ./person.jpg #ffffff
image-process replace-bg ./person.jpg ./background.jpg
放大
image-process upscale ./photo.jpg -s 2
image-process upscale ./photo.jpg -w 2000 -h 3000
安装
bash
cd E:\cvte\skills\image-process
npm install
依赖项
- - @imgly/background-removal-node - AI背景移除
- sharp - 高性能图像处理