feat(smart-crop): overhaul with face detection, social presets, and 3 modes

Replace the confusing 2-mode smart crop with a clear 3-mode system:
- Subject Focus: Sharp attention/entropy saliency crop with social media presets
- Face Focus: MediaPipe face detection with headshot framing presets
- Auto Trim: Border removal with optional pad-to-square

Adds detectFaces() to AI package, face preset constants, backward
compatibility for old mode names, and comprehensive integration tests.
This commit is contained in:
Siddharth Kumar Sah
2026-04-13 00:47:53 +08:00
parent 29fafd0722
commit 92d4d2d9c6
9 changed files with 798 additions and 277 deletions
+13 -3
View File
@@ -780,7 +780,7 @@ paths:
post:
tags: [Tools]
summary: Smart crop
description: Automatically crop to the most interesting region at the specified dimensions.
description: Smart crop with three modes - subject focus, face focus, or auto trim.
security:
- bearerAuth: []
requestBody:
@@ -799,8 +799,18 @@ paths:
type: string
description: |
JSON string with options:
- `width` (integer, required) — Target width in pixels
- `height` (integer, required) — Target height in pixels
- `mode` (string) — "subject" (default), "face", or "trim"
- `strategy` (string) — "attention" (default) or "entropy" (subject mode)
- `width` (integer) — Target width in pixels (default 1080)
- `height` (integer) — Target height in pixels (default 1080)
- `padding` (integer 0-50) — Padding percentage around focus area
- `facePreset` (string) — "closeup", "head-shoulders", "upper-body", "half-body" (face mode)
- `sensitivity` (number 0-1) — Face detection sensitivity (face mode)
- `threshold` (integer 0-255) — Trim tolerance (trim mode)
- `padToSquare` (boolean) — Pad to square after trimming (trim mode)
- `padColor` (string) — Hex color for padding (trim mode)
- `targetSize` (integer) — Target size for padded output (trim mode)
- `quality` (integer 1-100) — Output quality
responses:
"200":
description: Processed image