Click to upload or drag and drop

PNG, JPG, WebP up to 10MB

No image selected

Upload an image to get started

Integrate Smart Crop

Use the fal.ai API to add intelligent focal point detection and smart cropping to your applications.

How it works

1

Detect Focal Point

Send your image to the moondream3-preview/point endpoint with prompt "focal point"

2

Get Coordinates

Receive normalized (0-1) x,y coordinates representing the most important point in the image

3

Calculate Crop

Use the focal point as center, apply your target aspect ratio, and clamp to image boundaries

Code Examples

Install the fal.ai client:

npm install @fal-ai/client
1import { fal } from "@fal-ai/client";
2
3// Detect focal point
4const result = await fal.subscribe("fal-ai/moondream3-preview/point", {
5  input: {
6    image_url: "https://example.com/your-image.jpg",
7    prompt: "focal point",
8  },
9  logs: true,
10  onQueueUpdate: (update) => {
11    if (update.status === "IN_PROGRESS") {
12      update.logs.map((log) => log.message).forEach(console.log);
13    }
14  },
15});
16
17// Get focal point coordinates (normalized 0-1)
18const focalPoint = result.data.points[0];
19console.log(`Focal point: x=${focalPoint.x}, y=${focalPoint.y}`);
20
21// Calculate crop area centered on focal point
22function calculateCrop(imageWidth, imageHeight, focalX, focalY, aspectRatio) {
23  const [ratioW, ratioH] = aspectRatio.split(":").map(Number);
24  const targetAspect = ratioW / ratioH;
25  const imageAspect = imageWidth / imageHeight;
26
27  let cropWidth, cropHeight;
28  if (imageAspect > targetAspect) {
29    cropHeight = imageHeight;
30    cropWidth = cropHeight * targetAspect;
31  } else {
32    cropWidth = imageWidth;
33    cropHeight = cropWidth / targetAspect;
34  }
35
36  let cropX = focalX * imageWidth - cropWidth / 2;
37  let cropY = focalY * imageHeight - cropHeight / 2;
38
39  cropX = Math.max(0, Math.min(cropX, imageWidth - cropWidth));
40  cropY = Math.max(0, Math.min(cropY, imageHeight - cropHeight));
41
42  return { x: cropX, y: cropY, width: cropWidth, height: cropHeight };
43}
44
45const crop = calculateCrop(1920, 1080, focalPoint.x, focalPoint.y, "1:1");

Need more details? Check out the full API documentation.

API Reference