Skip to content
SENVENLI UI

Image cropper

Frames one picked image to the shape a surface needs: pan, zoom, rotate, an aspect preset, and the output as a file.
Crop to a cover photo
import { ImageCropper } from "@senvenli/react/form";

Examples

Aspect presets

When one image feeds several surfaces, people choose the shape first.

After a file is picked

FileTrigger checks the type and size, then the cropper frames the picked file.

Guidelines

When to use it

  • Before an uploaded image is saved: a cover photo, an avatar, a logo.

Use something else when

  • Files are kept as picked, without framing. File upload
  • The picture is only shown. Image

Accessibility

Keyboard

KeysWhat happens
Arrow keysMove the image in the frame.
+ / -Zoom in or out.

Built in

  • The frame announces its position and zoom.

You provide

  • What is being cropped, as its name.

API reference

ImageCropper

srcRequired
string | Blob

The picked file (from FileTrigger, already checked for size and type), or an image URL. A URL from another origin is loaded with CORS so the crop can be read back: its server must send Access-Control-Allow-Origin, or the image does not open (rather than failing later at save).

labelRequired
string

What is being cropped ("Cover photo"); names the crop frame.

aspectRatio
ImageCropperAspectDefault 16 / 9

16:9 by default; "free" keeps the image's own shape. Ignored when presets are given.

aspectPresets
readonly ImageCropperPreset[]

Two or more shapes to choose from (a segmented control); the first is selected.

fit
CropFitDefault "cover"

cover (default) fills the frame; contain fits the whole image and leaves empty area.

background
stringDefault "#ffffff"

The empty area's colour in contain when the output has no alpha (JPEG). White by default.

outputType
CropOutputTypeDefault "image/jpeg"

image/jpeg by default. PNG and WebP keep transparency.

quality
numberDefault 0.9

0–1, for JPEG and WebP. 0.9 by default.

maxBytes
number

The largest file the surface takes, in bytes. A JPEG or WebP over it is encoded again at a quality 0.1 lower each time, down to minimumQuality; when even that is over, or a PNG is, nothing is handed to onCrop and the cropper says the image is over the limit (a smaller crop, by zooming in, or another image fits).

minimumQuality
number

The lowest quality maxBytes may step down to (0.9 keeps a hero or slide sharp). 0.1 by default; at most quality.

maxOutputSize
numberDefault 4096

The output's long edge in px at most (a surface's size, 2560 for a full-width photo): larger crops scale down, never up. 4096 by default, so a 48 MP phone photo stays within every browser's canvas limit.

minOutputSize
number

Under this long edge the warning shows; it never blocks.

fileName
string

The output file's name without extension; the source file's name by default.

onCropRequired
(file: File, result: ImageCropperResult) => unknown
onCancel
() => void