import { useState } from "react"; import { useFileStore } from "@/stores/file-store"; import { useToolProcessor } from "@/hooks/use-tool-processor"; import { Download, Loader2 } from "lucide-react"; const ASPECT_PRESETS = [ { label: "1:1 Square", w: 1080, h: 1080 }, { label: "16:9 Landscape", w: 1920, h: 1080 }, { label: "9:16 Portrait", w: 1080, h: 1920 }, { label: "4:3 Standard", w: 1440, h: 1080 }, { label: "3:2 Photo", w: 1620, h: 1080 }, { label: "Custom", w: 0, h: 0 }, ]; export function SmartCropSettings() { const { files } = useFileStore(); const { processFiles, processing, error, downloadUrl, originalSize, processedSize } = useToolProcessor("smart-crop"); const [width, setWidth] = useState("1080"); const [height, setHeight] = useState("1080"); const [preset, setPreset] = useState("1:1 Square"); const handlePreset = (label: string) => { setPreset(label); const p = ASPECT_PRESETS.find((a) => a.label === label); if (p && p.w > 0) { setWidth(String(p.w)); setHeight(String(p.h)); } }; const handleProcess = () => { const w = Number(width); const h = Number(height); if (w > 0 && h > 0) { processFiles(files, { width: w, height: h }); } }; const hasFile = files.length > 0; const canProcess = Number(width) > 0 && Number(height) > 0; return (
{/* Aspect ratio preset */}
{/* Width / Height */}
{ setWidth(e.target.value); setPreset("Custom"); }} min={1} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{ setHeight(e.target.value); setPreset("Custom"); }} min={1} className="w-full mt-0.5 px-2 py-1.5 rounded border border-border bg-background text-sm text-foreground" />
{/* Info */}

Uses entropy-based attention detection to find the most interesting region of the image and crops to it.

{/* Error */} {error &&

{error}

} {/* Size info */} {originalSize != null && processedSize != null && (

Original: {(originalSize / 1024).toFixed(1)} KB

Cropped: {(processedSize / 1024).toFixed(1)} KB

)} {/* Process button */} {/* Download */} {downloadUrl && ( Download )}
); }