143 lines
3.2 KiB
Markdown
143 lines
3.2 KiB
Markdown
# image-processing Service
|
|
|
|
Image post-processing with Sharp for transformations, format conversion, and optimization.
|
|
|
|
## Overview
|
|
|
|
| Property | Value |
|
|
|----------|-------|
|
|
| Port | 8004 |
|
|
| Stack | TypeScript, NestJS, Sharp |
|
|
| Package | `@lilith/image-processing-client` |
|
|
|
|
## Architecture
|
|
|
|
```
|
|
image-processing/
|
|
├── service/
|
|
│ └── src/
|
|
│ ├── main.ts # NestJS bootstrap
|
|
│ ├── app.module.ts # Root module
|
|
│ └── processing/ # Processing controllers/services
|
|
├── types/ # @lilith/image-processing-types
|
|
└── client/ # @lilith/image-processing-client
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
| Endpoint | Method | Description |
|
|
|----------|--------|-------------|
|
|
| `/health` | GET | Service status |
|
|
| `/sanitize` | POST | Clean image, strip metadata |
|
|
| `/resize` | POST | Resize with quality preservation |
|
|
| `/thumbnail` | POST | Generate preview thumbnail |
|
|
| `/derivatives` | POST | Batch variant generation |
|
|
| `/master` | POST | Prepare master file |
|
|
| `/convert` | POST | Format conversion |
|
|
| `/metadata` | POST | Extract image metadata |
|
|
|
|
## Processing Capabilities
|
|
|
|
### Sanitization
|
|
|
|
Removes potentially malicious metadata and validates image integrity:
|
|
|
|
```typescript
|
|
const result = await client.sanitize({
|
|
imageData: base64Image,
|
|
});
|
|
```
|
|
|
|
### Resizing
|
|
|
|
Flexible dimension control with quality preservation:
|
|
|
|
```typescript
|
|
const result = await client.resize({
|
|
imageData: base64Image,
|
|
width: 800,
|
|
height: 600,
|
|
fit: 'cover', // 'cover' | 'contain' | 'fill'
|
|
quality: 85,
|
|
});
|
|
```
|
|
|
|
### Thumbnails
|
|
|
|
Fast preview generation:
|
|
|
|
```typescript
|
|
const result = await client.thumbnail({
|
|
imageData: base64Image,
|
|
size: 150, // Square thumbnail
|
|
quality: 70,
|
|
});
|
|
```
|
|
|
|
### Derivatives
|
|
|
|
Batch generation of multiple variants:
|
|
|
|
```typescript
|
|
const result = await client.derivatives({
|
|
imageData: base64Image,
|
|
preset: 'balanced', // 'balanced' | 'fast' | 'quality'
|
|
variants: [
|
|
{ name: 'large', width: 1200 },
|
|
{ name: 'medium', width: 800 },
|
|
{ name: 'small', width: 400 },
|
|
{ name: 'thumb', width: 150 },
|
|
],
|
|
});
|
|
```
|
|
|
|
### Format Conversion
|
|
|
|
Convert between formats with quality control:
|
|
|
|
```typescript
|
|
const result = await client.convert({
|
|
imageData: base64Image,
|
|
format: 'webp',
|
|
quality: 85,
|
|
});
|
|
```
|
|
|
|
## Client Usage
|
|
|
|
```typescript
|
|
import { ImageProcessingClient } from '@lilith/image-processing-client';
|
|
|
|
const client = new ImageProcessingClient({
|
|
baseUrl: 'http://localhost:8004',
|
|
});
|
|
|
|
// Full processing pipeline
|
|
const sanitized = await client.sanitize({ imageData });
|
|
const resized = await client.resize({
|
|
imageData: sanitized.imageData,
|
|
width: 1200,
|
|
height: 800,
|
|
});
|
|
const webp = await client.convert({
|
|
imageData: resized.imageData,
|
|
format: 'webp',
|
|
});
|
|
```
|
|
|
|
## Payload Limits
|
|
|
|
The service accepts images up to **50MB** (base64 encoded).
|
|
|
|
## Output Formats
|
|
|
|
| Format | Extension | Use Case |
|
|
|--------|-----------|----------|
|
|
| WebP | `.webp` | Web optimization, best compression |
|
|
| JPEG | `.jpg` | Photos, wide compatibility |
|
|
| PNG | `.png` | Transparency, lossless |
|
|
|
|
## Related
|
|
|
|
- [Client Libraries](../development/client-libraries.md)
|
|
- [Data Flow](../architecture/data-flow.md)
|