image-crop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Image Crop

图片裁剪

Crops an image to specified dimensions centered on a configurable focal point. The crop region is calculated to center on the focal point while staying within image bounds.
围绕可配置的焦点将图片裁剪为指定尺寸。裁剪区域会以焦点为中心计算,同时确保在图片边界范围内。

Command

命令

bash
agent-media image crop --in <path> --width <px> --height <px> [options]
bash
agent-media image crop --in <path> --width <px> --height <px> [options]

Inputs

输入参数

OptionRequiredDescription
--in
YesInput file path or URL
--width
YesWidth of crop area in pixels
--height
YesHeight of crop area in pixels
--focus-x
NoFocal point X position 0-100 (default: 50 = center)
--focus-y
NoFocal point Y position 0-100 (default: 50 = center)
--dpi
NoDPI/density for output (default: 300)
--out
NoOutput path, filename or directory (default: ./)
--provider
NoProvider to use (default: local)
选项是否必填说明
--in
输入文件路径或URL
--width
裁剪区域的宽度(像素)
--height
裁剪区域的高度(像素)
--focus-x
焦点X轴位置 0-100(默认值:50 = 居中)
--focus-y
焦点Y轴位置 0-100(默认值:50 = 居中)
--dpi
输出文件的DPI/密度(默认值:300)
--out
输出路径、文件名或目录(默认值:./)
--provider
使用的处理提供商(默认值:local)

Output

输出

Returns a JSON object with the cropped image path:
json
{
  "ok": true,
  "media_type": "image",
  "action": "crop",
  "provider": "local",
  "output_path": "cropped_123_abc.png",
  "mime": "image/png",
  "bytes": 45678
}
返回包含裁剪后图片路径的JSON对象:
json
{
  "ok": true,
  "media_type": "image",
  "action": "crop",
  "provider": "local",
  "output_path": "cropped_123_abc.png",
  "mime": "image/png",
  "bytes": 45678
}

Examples

示例

Crop to 800x600 centered (default focal point):
bash
agent-media image crop --in photo.jpg --width 800 --height 600
Crop with focal point at top-left area (20% from left, 30% from top):
bash
agent-media image crop --in photo.jpg --width 800 --height 600 --focus-x 20 --focus-y 30
Crop from URL with custom output:
bash
agent-media image crop --in https://example.com/image.jpg --width 1024 --height 768 --out ./output
裁剪为800x600尺寸并居中(默认焦点):
bash
agent-media image crop --in photo.jpg --width 800 --height 600
将焦点设为左上角区域(距左侧20%,距顶部30%)进行裁剪:
bash
agent-media image crop --in photo.jpg --width 800 --height 600 --focus-x 20 --focus-y 30
从URL获取图片并裁剪,指定自定义输出路径:
bash
agent-media image crop --in https://example.com/image.jpg --width 1024 --height 768 --out ./output

Providers

处理提供商

  • local (default) - Uses Sharp library, no API key required
  • local(默认)- 使用Sharp库,无需API密钥