Face detection and saliency-based automatic cropping.

Smart Crop

Smart crop automatically finds the most important region of an image and crops to keep it in frame. Works with any fit=cover or fit=crop resize.

Saliency-based (g=auto)

Analyzes the image to find the most visually interesting region using:

  1. Edge energy — Sobel gradient magnitude detects areas with high detail
  2. Skin-tone detection — YCbCr color space identifies potential subjects
  3. Center bias — Gaussian falloff from center (subjects tend to be centered)
  4. Weighted centroid — Focal point computed from top 10% of saliency values
?w=400&h=400&fit=cover&g=auto

Best for: landscapes, product shots, editorial images, any image where you want the "interesting part" preserved.

Face detection (g=face)

Detects the largest face-like region and centers the crop on it:

  1. Skin color detection in YCbCr color space (robust across skin tones and lighting)
  2. Morphological close — fills small gaps in detected regions
  3. Connected component analysis — groups skin pixels into regions
  4. Face filtering — selects the largest region with face-like aspect ratio (0.4-1.8)
  5. Fallback — if no face is found, falls back to g=auto
?w=200&h=200&fit=cover&g=face

Best for: profile photos, team headshots, avatars, social media cards.

Performance

Smart crop runs on a 128px thumbnail of the image, so the analysis adds ~1-2ms to transform time. The full-resolution crop coordinates are computed from the thumbnail focal point.

Examples

# Original → square avatar with face crop
?w=200&h=200&fit=cover&g=face

# Hero banner crop → keep the interesting part
?w=1200&h=400&fit=cover&g=auto

# Thumbnail grid → smart crop each image
?w=300&h=300&fit=cover&g=auto