Image crop
ProFrames a photo before upload: drag, pinch or zoom it behind a fixed frame, and get the crop in the original pixels. Not an M3 component (@windmorph/react-pro).
import { ImageCropDialog, ImageCropper } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
An image crop frames a photo before it's uploaded: people drag and zoom the photo behind a fixed frame, then confirm. It is not an M3 component: it comes from @windmorph/react-pro, built from the library's Dialog, Slider and Icon buttons. ImageCropDialog is full screen on compact windows, narrow (below 600px wide) or short (below 480px tall, a phone held sideways), and a basic dialog on larger ones; ImageCropper is the same area inline.
It reports a rectangle, not an image: the crop in the original photo's pixels. Upload the original file with it and crop on the server, so the photo keeps its full quality and nothing is re-encoded in the browser. The rectangle is measured after the photo's EXIF orientation, so rotate first: sharp(file).rotate().extract(crop).
Behaviour
- A pointer drags the photo and two fingers pinch to zoom. Ctrl or ⌘ with the wheel (one step a notch; a trackpad pinch follows smoothly) zooms around the pointer; a plain wheel scrolls the page, as in Media viewer.
- Inline, a vertical swipe over the photo scrolls the page while the photo has nothing to move vertically (a landscape photo at zoom 1), so a cropper in a form never traps the page. A portrait photo, or one zoomed in, takes the swipe to move. Inside
ImageCropDialogevery gesture moves the photo. The area carriesdata-zoomedwhile zoomed in. - When Zoom out or Zoom in reaches its limit and turns itself off, focus moves to the other zoom button (or the area), so it never drops to the page.
ImageCropDialogcaps the photo frame's height to the window, so the zoom controls and the actions stay in view inside the dialog's 56px margins.
When not to use
For photos shown as uploaded (attachments, documents, chat images), skip the crop and upload the file.
See also
- Dialog: A modal surface for a focused task or a decision, with a title, content and actions, or full screen on compact windows.
- Slider: Chooses a value or a range on a continuous or stepped scale, in five sizes.
- Avatar: A picture with an initials or icon fallback, badges, 35 Expressive shapes and groups. Not an M3 component (@windmorph/react-pro).