mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
- Create 53 per-tool VitePress documentation pages with accurate parameters from Zod schemas, example requests, and response formats - Add root llms.txt for LLM-friendly repo browsing - Fix OpenAPI spec: add auth and 422 error schemas to edit-metadata/inspect and strip-metadata/inspect sub-routes - Fix tool count inconsistency (52 -> 53) across landing site, e2e tests, and local docs - Rename color-adjustments.ts to adjust-colors.ts to match tool ID - Update VitePress sidebar with all 8 tool categories and top nav
2.3 KiB
2.3 KiB
description
| description |
|---|
| Replace a specific color in an image with another color or make it transparent. |
Replace & Invert Color
Replace pixels matching a source color with a target color, or make them transparent. Uses Euclidean distance in RGB space with configurable tolerance for smooth blending at color boundaries.
API Endpoint
POST /api/v1/tools/replace-color
Accepts multipart form data with an image file and a JSON settings field.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| sourceColor | string | No | "#FF0000" |
Hex color to find (format: #RRGGBB) |
| targetColor | string | No | "#00FF00" |
Hex color to replace with (format: #RRGGBB) |
| makeTransparent | boolean | No | false |
Make matching pixels transparent instead of replacing with target color |
| tolerance | number | No | 30 |
Color matching tolerance (0 to 255). Higher values match a wider range of similar colors |
Example Request
curl -X POST http://localhost:1349/api/v1/tools/replace-color \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@photo.jpg" \
-F 'settings={"sourceColor": "#FF0000", "targetColor": "#0000FF", "tolerance": 40}'
Make a green background transparent:
curl -X POST http://localhost:1349/api/v1/tools/replace-color \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@greenscreen.png" \
-F 'settings={"sourceColor": "#00FF00", "makeTransparent": true, "tolerance": 50}'
Example Response
{
"jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"downloadUrl": "/api/v1/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890/photo.png",
"originalSize": 2450000,
"processedSize": 2100000
}
Notes
- Color matching uses Euclidean distance in RGB space, scaled by
tolerance * sqrt(3). - Replacement blending is proportional to color distance: pixels closer to the source color receive more of the target color, creating smooth transitions.
- When
makeTransparentistrue, the output is forced to PNG (or WebP/AVIF) if the input format does not support alpha channels (e.g., JPEG). - A tolerance of 0 matches only the exact source color. Higher values (50+) will match a broader range of similar hues.
- Output format matches the input format unless transparency is needed and the input format lacks alpha support.