# image-resize

> III engine image resize worker (JPEG/PNG/WebP, EXIF orient, scale-to-fit / crop-to-fit)

| field | value |
|-------|-------|
| version | 0.1.8 |
| type | binary |
| repo | https://github.com/iii-hq/workers |
| supported_targets | x86_64-apple-darwin, aarch64-apple-darwin, i686-pc-windows-msvc, x86_64-pc-windows-msvc, aarch64-pc-windows-msvc, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-unknown-linux-musl, armv7-unknown-linux-gnueabihf |
| author | iii |

## installation

```sh
iii worker add image-resize@0.1.8
```

## configuration

```yaml
- height: 200
  quality:
    jpeg: 85
    webp: 80
  strategy: scale-to-fit
  width: 200
```

## readme

# image-resize

A high-performance image resizing worker built for production workloads.

## Installation

```bash
iii worker add image-resize
```

## Configuration

Add the worker to your pipeline configuration:

```yaml
- name: image-resize
  config:
    height: 200
    quality:
      jpeg: 85
      webp: 80
    strategy: scale-to-fit
    width: 200
```

### Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `width` | number | 200 | Target width in pixels |
| `height` | number | 200 | Target height in pixels |
| `strategy` | string | `scale-to-fit` | Resize strategy: `scale-to-fit`, `crop`, `fill`, `contain` |
| `quality.jpeg` | number | 85 | JPEG output quality (1-100) |
| `quality.webp` | number | 80 | WebP output quality (1-100) |

### Strategies

- **scale-to-fit** — Resize to fit within the given dimensions, preserving aspect ratio
- **crop** — Crop to exact dimensions from center
- **fill** — Fill the area, stretching if necessary
- **contain** — Contain within dimensions, adding padding if needed

## Usage

```typescript
import { pipeline } from '@iii/core';

const result = await pipeline.run('image-resize', {
  input: buffer,
  params: { width: 400, height: 300, strategy: 'crop' }
});
```

## Performance

Benchmarks on a standard worker instance (2 vCPU, 512MB):

| Format | Avg Latency | Throughput |
|--------|-------------|------------|
| JPEG | 12ms | ~83 ops/s |
| WebP | 18ms | ~55 ops/s |
| PNG | 24ms | ~41 ops/s |

## License

Apache 2.0

## api reference

```json
{
  "functions": [
    {
      "description": "Resize an image via channel I/O",
      "metadata": {},
      "name": "image_resize::resize",
      "request_schema": {
        "properties": {
          "input_channel": {
            "description": "StreamChannelRef (read) carrying metadata text + image binary",
            "type": "object"
          },
          "metadata": {
            "description": "Optional inline ImageMetadata override",
            "properties": {
              "format": {
                "description": "Source image format",
                "enum": [
                  "jpeg",
                  "png",
                  "webp"
                ],
                "type": "string"
              },
              "height": {
                "type": "integer"
              },
              "output_format": {
                "description": "Desired output format (defaults to source format)",
                "enum": [
                  "jpeg",
                  "png",
                  "webp"
                ],
                "type": "string"
              },
              "quality": {
                "type": "integer"
              },
              "strategy": {
                "enum": [
                  "scale-to-fit",
                  "crop-to-fit"
                ],
                "type": "string"
              },
              "target_height": {
                "type": "integer"
              },
              "target_width": {
                "type": "integer"
              },
              "width": {
                "type": "integer"
              }
            },
            "type": "object"
          },
          "output_channel": {
            "description": "StreamChannelRef (write) for thumbnail output",
            "type": "object"
          }
        },
        "required": [
          "input_channel",
          "output_channel"
        ],
        "type": "object"
      },
      "response_schema": {
        "properties": {
          "format": {
            "type": "string"
          },
          "height": {
            "type": "integer"
          },
          "strategy": {
            "type": "string"
          },
          "width": {
            "type": "integer"
          }
        },
        "type": "object"
      }
    }
  ],
  "triggers": [
    {
      "description": "Log event trigger",
      "invocation_schema": {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "definitions": {
          "LogLevel": {
            "enum": [
              "all",
              "debug",
              "info",
              "warn",
              "error"
            ],
            "type": "string"
          }
        },
        "properties": {
          "level": {
            "anyOf": [
              {
                "$ref": "#/definitions/LogLevel"
              },
              {
                "type": "null"
              }
            ],
            "default": "all",
            "description": "Minimum log level to trigger on"
          }
        },
        "title": "LogTriggerConfig",
        "type": "object"
      },
      "metadata": {},
      "name": "log",
      "return_schema": {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "properties": {
          "attributes": {
            "description": "Log attributes"
          },
          "body": {
            "description": "Log message body",
            "type": "string"
          },
          "instrumentation_scope_name": {
            "description": "Instrumentation scope name",
            "type": "string"
          },
          "instrumentation_scope_version": {
            "description": "Instrumentation scope version",
            "type": "string"
          },
          "observed_timestamp_unix_nano": {
            "description": "Observed timestamp in nanoseconds",
            "format": "uint64",
            "minimum": 0,
            "type": "integer"
          },
          "resource": {
            "description": "OpenTelemetry resource"
          },
          "service_name": {
            "description": "Service name",
            "type": "string"
          },
          "severity_number": {
            "description": "Severity number (OpenTelemetry)",
            "format": "uint32",
            "minimum": 0,
            "type": "integer"
          },
          "severity_text": {
            "description": "Severity text (e.g. INFO, ERROR)",
            "type": "string"
          },
          "span_id": {
            "description": "Span ID",
            "type": "string"
          },
          "timestamp_unix_nano": {
            "description": "Log timestamp in nanoseconds",
            "format": "uint64",
            "minimum": 0,
            "type": "integer"
          },
          "trace_id": {
            "description": "Trace ID",
            "type": "string"
          }
        },
        "required": [
          "attributes",
          "body",
          "instrumentation_scope_name",
          "instrumentation_scope_version",
          "observed_timestamp_unix_nano",
          "resource",
          "service_name",
          "severity_number",
          "severity_text",
          "span_id",
          "timestamp_unix_nano",
          "trace_id"
        ],
        "title": "LogCallRequest",
        "type": "object"
      }
    }
  ]
}
```
