📂 Add new directory for image-scale-cli tool

This commit is contained in:
2026-04-11 11:10:53 +08:00
parent 82e293f4c2
commit 9454512b7b
60 changed files with 3186 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-04-11

View File

@@ -0,0 +1,34 @@
## Context
A Deno-based TypeScript utility is needed to scale images to fixed dimensions. The solution must work in the Deno runtime environment and support common image formats.
## Goals / Non-Goals
**Goals:**
- Scale images to specified fixed dimensions
- Support PNG, JPEG, WebP, and GIF formats
- Preserve aspect ratio with configurable options
- Provide a simple CLI interface
- Run on Deno runtime
**Non-Goals:**
- Advanced image editing (filters, cropping, rotation)
- Server-side API or web interface
- Real-time image processing pipelines
## Decisions
| Decision | Choice | Rationale |
|----------|--------|-----------|
| Runtime | Deno | User specified TypeScript with Deno - built-in TypeScript support, modern security model |
| Image library | `deno-image` or similar Deno-compatible library | Native Deno support, no Node.js compatibility layer needed |
| CLI approach | Deno args parsing | Simple, no external dependencies for argument handling |
| Aspect ratio | Configurable (stretch or fit) | Flexibility for different use cases |
## Risks / Trade-offs
| Risk | Mitigation |
|------|------------|
| Limited Deno image processing libraries | Evaluate available options; fallback to WASM-based solutions if needed |
| Performance with large images | Add warnings for very large files; consider streaming for batch operations |
| Format compatibility | Test with common formats; document supported formats clearly |

View File

@@ -0,0 +1,24 @@
## Why
Images need to be scaled to consistent dimensions for uniform display across the application. This change adds a Deno-based TypeScript utility to scale images to fixed sizes, ensuring visual consistency and optimized file sizes.
## What Changes
- New CLI utility to scale images to specified dimensions
- Support for common image formats (PNG, JPEG, WebP, GIF)
- Configurable output size with aspect ratio preservation options
- Batch processing capability for multiple images
## Capabilities
### New Capabilities
- `image-scaling`: Core capability to resize images to fixed dimensions using Deno
### Modified Capabilities
-
## Impact
- New Deno-based image processing module
- Dependencies on image processing libraries compatible with Deno
- CLI interface for image scaling operations

View File

@@ -0,0 +1,57 @@
## ADDED Requirements
### Requirement: Scale image to fixed dimensions
The system SHALL resize images to specified width and height dimensions while supporting configurable aspect ratio handling.
#### Scenario: Scale with exact dimensions (stretch)
- **WHEN** user provides width and height with stretch mode
- **THEN** image is resized to exact dimensions regardless of original aspect ratio
#### Scenario: Scale with fit mode (preserve aspect ratio)
- **WHEN** user provides width and height with fit mode
- **THEN** image is resized to fit within dimensions while preserving aspect ratio
#### Scenario: Scale with cover mode (preserve aspect ratio)
- **WHEN** user provides width and height with cover mode
- **THEN** image is resized to cover dimensions while preserving aspect ratio, cropping excess
### Requirement: Support multiple image formats
The system SHALL process PNG, JPEG, WebP, and GIF image formats for both input and output.
#### Scenario: Process PNG image
- **WHEN** user provides a PNG file as input
- **THEN** system successfully scales and outputs the image
#### Scenario: Process JPEG image
- **WHEN** user provides a JPEG file as input
- **THEN** system successfully scales and outputs the image
#### Scenario: Process WebP image
- **WHEN** user provides a WebP file as input
- **THEN** system successfully scales and outputs the image
#### Scenario: Process GIF image
- **WHEN** user provides a GIF file as input
- **THEN** system successfully scales and outputs the image
### Requirement: Batch processing
The system SHALL process multiple images in a single operation when provided with a directory or multiple file paths.
#### Scenario: Process directory of images
- **WHEN** user provides a directory path
- **THEN** all supported images in the directory are scaled
#### Scenario: Process multiple files
- **WHEN** user provides multiple file paths
- **THEN** all specified images are scaled
### Requirement: CLI interface
The system SHALL provide a command-line interface for specifying input, output, and scaling options.
#### Scenario: Scale single image
- **WHEN** user runs command with input file, output path, width, and height
- **THEN** scaled image is saved to output path
#### Scenario: Invalid input handling
- **WHEN** user provides non-existent file or unsupported format
- **THEN** system displays clear error message and exits with non-zero code

View File

@@ -0,0 +1,35 @@
## 1. Project Setup
- [x] 1.1 Initialize Deno project with deno.json configuration
- [x] 1.2 Set up directory structure (src/, cli.ts)
- [x] 1.3 Add image processing dependency compatible with Deno
## 2. Core Image Scaling Implementation
- [x] 2.1 Create image loader module supporting PNG, JPEG, WebP, GIF
- [x] 2.2 Implement scale function with exact dimensions (stretch) mode
- [x] 2.3 Implement scale function with fit mode (preserve aspect ratio)
- [x] 2.4 Implement scale function with cover mode (preserve aspect ratio, crop)
- [x] 2.5 Create image saver module with format detection
## 3. Batch Processing
- [x] 3.1 Implement directory scanner for supported image formats
- [x] 3.2 Create batch processor with progress reporting
- [x] 3.3 Add error handling for failed images in batch
## 4. CLI Interface
- [x] 4.1 Create CLI argument parser (input, output, width, height, mode)
- [x] 4.2 Implement single image scaling command
- [x] 4.3 Implement batch scaling command (directory/multiple files)
- [x] 4.4 Add error messages and exit codes for invalid input
- [x] 4.5 Add help documentation (--help flag)
## 5. Testing & Validation
- [x] 5.1 Create test images for each supported format
- [x] 5.2 Write unit tests for scale functions
- [x] 5.3 Write integration tests for CLI commands
- [x] 5.4 Test batch processing with mixed formats
- [x] 5.5 Verify output dimensions match specifications