SuperAPI AI Directory

image-resizer

Design & creation

View repository

Updated 10-16 09:59

About this skill

Skill Overview

Skill Name: image-resizer
Core Features: Image resizing and compression, supports resizing by pixel width and height, ratio, and maximum size, as well as smart compression to a specified file size
Applicable Scenarios:

  • Resize images to specified pixel dimensions (e.g., 800×600)
  • Scale images by ratio (e.g., 50% reduction, 200% enlargement)
  • Limit maximum size (maintain ratio, e.g., maximum 1920×1080)
  • Crop to specified aspect ratio (e.g., 16:9, 4:3)
  • Compress images to a specified size (e.g., compress to ≤500KB)
  • Batch process multiple images

Script Usage Instructions

Install Dependencies

cd scripts
npm install

Basic Usage

node resize_image.js <输入图片> [选项]

Option Description

Parameter Short Form Description Example
--width -w Target width (pixels) -w 800
--height -h Target height (pixels) -h 600
--scale -s Scale ratio -s 0.5
--max-width - Maximum width (maintain ratio) --max-width 1920
--max-height - Maximum height (maintain ratio) --max-height 1080
--quality -q Output quality 1-100 -q 80
--size -S Target file size (KB), automatic compression -S 500
--format -f Output format: png|jpg|webp|original -f webp
--output -o Output path -o output.png
--aspect-ratio -a Target aspect ratio -a 16:9
--fit - Fit mode --fit cover

Fit Mode Description

Mode Description
cover Fill the entire area (may crop, default)
contain Fit completely within the area (may leave blank space)
fill Stretch to fill
inside Fit completely (shrink only)
outside Cover completely (enlarge only)

Usage Examples

Example 1: Resize to Specified Dimensions

node resize_image.js input.png -w 800 -h 600 -o output.png

Example 2: Scale by Ratio

node resize_image.js input.png -s 0.5 -o output.png

Example 3: Compress to Specified Size

node resize_image.js input.png -S 500 -o output.jpg

Example 4: Crop to Specified Aspect Ratio

node resize_image.js input.png -a 16:9 -o output.png

Example 5: Maximum Size Limit (Maintain Ratio)

node resize_image.png input.png --max-width 1920 --max-height 1080 -o output.png

Example 6: Convert to WebP and Compress

node resize_image.js input.png -f webp -q 80 -o output.webp

Typical Workflow

Workflow 1: Generate Website Thumbnails

  1. Read the original image
  2. Limit the maximum width to 1200px, maintain ratio
  3. Compress to ≤300KB
  4. Output as JPEG format
node resize_image.js photo.jpg --max-width 1200 -S 300 -f jpg -o thumbnail.jpg

Workflow 2: Generate Social Media Images

  1. Read the original image
  2. Resize to 1080×1080 square
  3. Compress to ≤500KB
node resize_image.js input.png -w 1080 -h 1080 -S 500 -o instagram.png

Workflow 3: Generate 16:9 Landscape Images

  1. Read the original image
  2. Crop to 16:9 ratio (centered)
  3. Compress to ≤200KB
node resize_image.js input.png -a 16:9 -S 200 -o 16_9.jpg

Skill File Structure

image-resizer/
├── SKILL.md                    # 技能主文件
└── scripts/
    ├── resize_image.js         # 图片处理脚本
    └── package.json            # 依赖配置

Dependency Description

  • sharp: Image processing library, supports conversion, cropping, and compression of formats such as PNG, JPEG, WebP, etc.