Cropper
A crop rectangle over an image, with no dependency: lock a ratio, mask a circle, rotate and flip, and crop on a server or in the browser.
Import
import { Cropper } from '@vitral/vue';Avatar
A circle locks the ratio to one and drops the handles: drag the crop, or zoom it. The preview beside it is the same picture under a smaller box, not a second render.
Use the arrow keys to move the crop, Shift with an arrow to resize it, Home and End for the corners.
A ratio, with handles
Eight handles for the pointer, hidden from assistive technology: the rectangle itself is the one tab stop.
Use the arrow keys to move the crop, Shift with an arrow to resize it, Home and End for the corners.
Without the thirds
The guide is on for a rectangle and off for a circle, where a rule of thirds means nothing. `grid` overrules either way.
Use the arrow keys to move the crop, Shift with an arrow to resize it, Home and End for the corners.
Free, with ratios and turns
A chooser locks the ratio; the quarter turns and the flips travel with the crop, so it keeps pointing at the same part of the picture.
Use the arrow keys to move the crop, Shift with an arrow to resize it, Home and End for the corners.
const crop = ref<CropValue>({ x: 0, y: 0, width: 0, height: 0, rotate: 0 });In a dialog
Where a cropper usually lives: a photograph is chosen, cropped over the page, and the profile changes only once it is accepted. The dialog gives the stage its width, so the crop is measured against what it is actually shown at.
The shape of it
Use the arrow keys to move the crop, Shift with an arrow to resize it, Home and End for the corners.
API
Read from packages/vue/src/components/Cropper/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| src | string | The image. Anything an `<img>` takes; a data or object URL included. |
| alt | string | Describes the picture, not the control. Without one the image is decorative. |
| aspect | number | string | null | Lock the crop to a ratio: `1`, `'16:9'`, or null to leave it free. |
| aspects | readonly CropAspect[] | Ratios to offer in the toolbar. Omit it and no chooser is drawn. |
| shape | 'rect' | 'circle' | `'circle'` masks the crop and the preview, and locks the ratio to 1. |
| handles | boolean | Draw the eight resize handles. Defaults to true for a rectangle, false for a circle. |
| rotatable | boolean | Offer the quarter turns and the flips. |
| zoomable | boolean | Offer a zoom slider. |
| grid | boolean | Draw the thirds over the crop while it is being moved. On by default for a rectangle and off for a circle, where a rule of thirds means nothing: the guide is for composing a frame, and a round crop has no corners to compose towards. |
| minWidth | number | The smallest crop, in the image's own pixels. |
| minHeight | number | — |
| height | number | string | The stage's height: a number is pixels. |
| previewSize | number | The live preview's size, in pixels. Zero draws none. |
| disabled | boolean | — |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| update:modelValue | value: CropValue | The crop, as it changes. |
| load | event: { width: number; height: number } | The image has loaded and its natural size is known. |
| change | value: CropValue | A drag of the crop or a handle has finished. |
Slots
| Name | Slot props | Description |
|---|---|---|
| toolbar | (props: { value: CropValue; reset: () => void }) | Replaces the toolbar. |
| preview | (props: { value: CropValue }) | Beside the preview, or in place of it. |