Short answer: when an avatar crop cuts off heads, debug the center rectangle first. Propose a content-aware box at upload, save that box with the source asset, and let the user move it before publishing the avatar.

That rule is deliberately boring. A center crop is deterministic, so it fails predictably on portraits: the face sits above the midpoint, or the requested square is much narrower than the camera frame. Resizing then preserves the wrong rectangle perfectly. The fix is to make the rectangle explicit data and give a person the last decision.

That is the diagnostic.

How do I debug an avatar crop when it cuts off heads?

Start with geometry. Record the source width and height, the requested avatar ratio, the crop strategy, and whether the final box came from an automatic proposal or a manual adjustment. If top-edge truncation clusters at one output ratio, the pipeline is behaving consistently; changing codecs or sharpening settings will not move the missing forehead. If your logs call the operation a centre crop, keep that spelling in the debug field so dashboards can find both terms.

I initially treated these reports as a resize problem. The resize was doing exactly what it was told. Once the crop box became a first-class record, a support report could be replayed against the immutable source instead of reconstructed from a flattened thumbnail. Store the source reference, the proposed box, the accepted box, and a revision number. A later rendition should consume the accepted box, never invent a new one.

For a B2B SaaS product, the upload path should create a fast preview and a durable proposal. Generate the common avatar sizes from the accepted box on demand or in a worker, depending on the profile-read SLO. If the source changes, invalidate those renditions; otherwise an old square can quietly survive beside a new portrait.

Should the proposal happen at upload or on demand?

Run smart cropping at upload, then render from the stored box. This keeps every client aligned and gives the adjustment UI something concrete to move. On-demand detection appears attractive because it writes less metadata, but it also puts a model decision on every first view and lets mobile, web, and email clients disagree about framing.

The capacity question is small but real: a proposal job must fit the upload worker's queue and the profile-read SLO must include rendition generation when a size is missing. Set a deadline for that worker, record a pending state, and make the fallback visible. A stale proposal is easier to diagnose than a silent center crop.

Option What it does well Boundary to document
Cloudinary gravity-based transformations Managed delivery and content-aware positioning work well for teams already using its transformation URLs. Transformation syntax and gravity semantics become part of the asset contract.
imgix URL rendering provides many derived sizes without running an image fleet. The application still has to supply or persist the focal point and the user's override.
imgproxy A focused, self-hostable proxy gives predictable request-time processing. It executes the box or gravity setting you provide; a separate detector is still needed for portrait-aware framing.
ImageMagick Local, deterministic geometry is easy to inspect in batch jobs. It applies a chosen rectangle and does not choose a face-aware one for you.

The managed choices reduce image infrastructure work, while ImageMagick keeps processing in your environment. None of those boundaries removes the product decision about who may correct a bad proposal. That is why the crop box belongs in your data model.

If a policy requires pixels to stay inside your network, or a team already operates an image proxy, a hosted gateway is the wrong boundary; choose imgproxy or ImageMagick and own the detector and on-call load. The trade-off is explicit.

One REST media layer can be useful when the platform team already has several backend services to operate. Infrai's positioning is one key and one bill across its capabilities, plus one REST API that is pure HTTP with no SDK to install, so the image worker does not add another credential or another invoice and any runtime can call it; the application still owns the source, box, approval state, and SLO. A Go worker and a browser-side service can send the same request shape. Its public, self-describing discovery surface exposes request and response schemas, and the documented capabilities include runnable examples in ten languages, which reduces adapter friction for non-Go clients. The discovery surface covers 295 routes across 20 modules, so the same convention can span adjacent backend jobs. Treat that as an operations convenience, not as evidence that an automatic crop is always right.

A safe Go path from proposal to approved box

Keep the proposal call separate from the final crop. The adapter below uses the verified smart-crop route, retries 429 responses with exponential backoff, honors Retry-After when present, and sends an idempotency key so a retry cannot create two durable proposals. The request body is rebuilt for each attempt, which matters because an HTTP client may consume the original reader.

package main import ( "bytes" "context" "encoding/json" "fmt" "io" "net/http" "os" "strconv" "time" ) func postSmartCrop(ctx context.Context, payload []byte, idemKey string) ([]byte, error) { baseURL := os.Getenv("IMAGE_API_BASE_URL") for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequestWithContext( ctx, http.MethodPost, baseURL+"/image/smart_crop", bytes.NewReader(payload), ) if err != nil { return nil, err } req.Header.Set("Authorization", "Bearer "+os.Getenv("INFRAI_API_KEY")) req.Header.Set("Content-Type", "application/json") req.Header.Set("Idempotency-Key", idemKey) resp, err := http.DefaultClient.Do(req) if err != nil { return nil, err } body, readErr := io.ReadAll(resp.Body) resp.Body.Close() if readErr != nil { return nil, readErr } if resp.StatusCode == http.StatusTooManyRequests { delay := time.Duration(1<<attempt) * 250 * time.Millisecond if retryAfter := resp.Header.Get("Retry-After"); retryAfter != "" { if seconds, parseErr := strconv.Atoi(retryAfter); parseErr == nil { delay = time.Duration(seconds) * time.Second } } time.Sleep(delay) continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return nil, fmt.Errorf("smart crop failed: %s: %s", resp.Status, body) } return body, nil } return nil, fmt.Errorf("smart crop rate-limit retry budget exhausted") } func main() { payload, err := json.Marshal(map[string]any{ "image_url": os.Getenv("SIGNED_SOURCE_URL"), "aspect_ratio": "1:1", }) if err != nil { panic(err) } result, err := postSmartCrop(context.Background(), payload, "avatar-proposal-asset-123-rev-1") if err != nil { panic(err) } fmt.Println(string(result)) } 

The example leaves the response schema to the capability contract you pin in your adapter. Validate that the returned box is inside the source image and that its aspect ratio matches the requested rendition before storing it. Use the crop route only after the user accepts or adjusts that box. Keep the API authorization header away from any signed source or output URL.

How do you verify the change and roll it back?

Build a small regression corpus: tall portraits, faces above center, hats, and images with generous background. For each item, assert that the proposed box stays within image bounds, that the rendered ratio is correct, and that rendering the same accepted box twice produces the same pixels. The useful numbers are the dimensions and the revision IDs you record, not a made-up accuracy score.

Release by account or rendition family. Watch the rate of manual moves and top-edge complaints against the center-crop baseline, and inspect samples rather than trusting a single aggregate. If the proposal service is unavailable, preserve the source and mark the rendition pending; use the last approved box, or a clearly labeled center crop if the product SLO requires an immediate image.

Rollback is then a data change: point the renderer at the previous accepted box revision. Do not overwrite the source, and do not discard the user's adjustment. The manual control is the safety valve because a detector cannot infer every person's preference, while a saved box gives support and engineering a precise artifact to inspect.

References