Image Cropper
Pan, zoom, and crop images in the browser with react-easy-crop. SonoJS wraps the stage and zoom slider; export a Blob via getCroppedImg.
Gallery
Square avatar crop with zoom slider and getCroppedImgUrl preview.
Loading…
Installation
CLI
Also needs
npx @sonojs/ui@latest add slidernpm i react-easy-cropUsage
image-cropper.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | - | Image URL or object URL to crop. |
| aspect | number | 1 | Crop aspect ratio (width / height). |
| cropShape | "rect" · "round" | "rect" | Rectangle or circular crop mask. |
| zoom | number | - | Controlled zoom level. |
| defaultZoom | number | 1 | Initial zoom when uncontrolled. |
| onZoomChange | (zoom: number) => void | - | Zoom change callback. |
| minZoom / maxZoom | number | 1 / 3 | Zoom bounds for the slider and gestures. |
| onCropComplete | (area, pixels) => void | - | Fires when a crop gesture ends. Use `pixels` with `getCroppedImg`. |
| showZoomSlider | boolean | true | Show the SonoJS zoom `Slider` under the stage. |
| showGrid | boolean | true | Rule-of-thirds grid overlay. |
| disabled | boolean | false | Disable pan, zoom, and the slider. |
| className | string | - | Merged onto the root wrapper. |
| stageClassName | string | - | Merged onto the crop stage (default `h-72`). |
Helpers
| Prop | Type | Default | Description |
|---|---|---|---|
| getCroppedImg | (src, pixels, options?) => Promise<Blob · null> | - | Canvas crop to a Blob (PNG by default). |
| getCroppedImgUrl | (src, pixels, options?) => Promise<string · null> | - | Object URL for previews. Revoke when done. |