Files
SnapOtter/apps/docs/ja/tools/image/smart-crop.md
T
SnapOtterandGitHub 4963ab3bbd feat(docs-i18n): translate all documentation into 20 languages
All 181 docs markdown files translated into 20 languages (apps/docs/<locale>/**). Companion to the i18n code PR; admin-merged because the file count exceeds GitHub's per-PR CI trigger limit. Validated by pnpm i18n:check (all surfaces, 0 stale/missing) and a clean all-locale docs build.
2026-07-11 13:52:47 +08:00

4.2 KiB
Raw Blame History

description, i18n_source_hash, i18n_provenance, i18n_output_hash
description i18n_source_hash i18n_provenance i18n_output_hash
SharpとAI顔検出を用いて、被写体・顔・エントロピーを認識しながら画像を賢くフレーミングして切り抜きます。 acbe1439c6d8 human 0effff4a667a

Smart Crop

被写体認識、顔認識、またはトリムベースのスマートな切り抜きです。Sharpのattention/entropy戦略とAI顔検出を用いて、賢くフレーミングします。

API Endpoint

POST /api/v1/tools/image/smart-crop

処理: 非同期(202を返し、/api/v1/jobs/{jobId}/progressをSSEでポーリングしてステータスを取得)

モデルバンドル: face-detection200〜300 MB- faceモードでのみ必要

Parameters

Parameter Type Required Default Description
file file Yes - 画像ファイル(multipart
mode string No "subject" 切り抜きモード: subject, face, trim。(従来値のattentioncontentはそれぞれsubjecttrimに対応します)
strategy string No "attention" subjectモードの戦略: attentionまたはentropy
width integer No - 目標の幅(ピクセル)
height integer No - 目標の高さ(ピクセル)
padding integer No 0 被写体周囲の余白の割合(0〜50
facePreset string No "head-shoulders" 顔フレーミングのプリセット: closeup, head-shoulders, upper-body, half-body
sensitivity number No 0.5 顔検出の感度(0〜1
threshold integer No 30 トリムモードでの背景検出のしきい値(0〜255)
padToSquare boolean No false トリム結果を正方形にパディングします
padColor string No "#ffffff" パディングの背景色
targetSize integer No - パディング済み出力の目標サイズ(ピクセル)
quality integer No - 出力品質(1〜100

Example Request

curl -X POST http://localhost:1349/api/v1/tools/image/smart-crop \
  -F "file=@portrait.jpg" \
  -F 'settings={"mode":"face","width":1080,"height":1080,"facePreset":"head-shoulders"}'

Response

Initial Response (202 Accepted)

{
  "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "async": true
}

Progress (SSE at /api/v1/jobs/{jobId}/progress)

event: progress
data: {"phase":"processing","percent":50}

Final Result (via SSE)

{
  "phase": "complete",
  "percent": 100,
  "result": {
    "jobId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "downloadUrl": "/api/v1/download/{jobId}/portrait_smartcrop.jpg",
    "originalSize": 500000,
    "processedSize": 320000
  }
}

Modes

Subject Mode

Sharpのattentionまたはentropy戦略を用いて、視覚的に最も興味深い領域を見つけ、その周囲を切り抜きます。

Face Mode

AIで顔を検出し、指定したfacePresetを用いて検出された顔の周囲を切り抜きます。顔が検出されない場合はsubjectモード(attention戦略)にフォールバックします。

Trim Mode

画像から均一な余白/背景を取り除きます。オプションで、指定した背景色と目標サイズで結果を正方形にパディングします。

Notes

  • このツールはexecutionHint: "long"を指定したcreateToolRouteファクトリを使用するため、SSE進捗とともに202を返します。
  • faceモードにはface-detectionモデルバンドル(200〜300 MB)が必要です。
  • subjectモードとtrimモードはAIモデルバンドルなしで動作します。
  • facePresetは、検出された顔をどれだけタイトにフレーミングするかを決定します。closeupが最もタイトで、half-bodyが最も広くなります。
  • 幅/高さが指定されない場合、デフォルトは1080x1080です。