Calm motion: animations on this site only fade, with no movement
Cropper
Crop and rotate an image, export the pixels
Cut a picture down before it is uploaded: an avatar, a cover, a product shot. The user frames the part they want. You get the rectangle, or the cropped image itself. To send the result, hand the blob to Uploader. To just show an image, use Img.
Basic
- Drag the frame to move it, a handle to resize it. With
aspectset (1,16 / 9) the shape is locked and only the corner handles show. Without it all eight do. - Keyboard: focus the frame, arrows move it by 1% (Shift by 10%), + and − resize it around the center. Each change is announced in pixels.
- The ↺ ↻ buttons turn the picture in 90° steps and reset the frame.
:controls="false"hides them. The exposedrotate(90)/rotate(-90)do the same. v-modelis the crop rectangle{ x, y, width, height, rotation }in pixels of the full-size image after rotation, so a server can repeat the crop exactly.- The exposed
toBlob({ type, quality, maxWidth })returns the cropped pixels at full resolution, or scaled down tomaxWidth. An image from another origin needs CORS headers (crossorigin="anonymous", the default) or the browser refuses to read it back. - A frame that cannot load shows an error message and emits
error.readyfires when the image is in.
Usage
ts
import { BlessCropper } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
src* | string | — | |
aspect | number | — | width / height of the result, e.g. `1` or `16 / 9`; leave out to crop freely |
crossorigin | "anonymous" | "use-credentials" | "anonymous" | `anonymous` lets `toBlob` read images from another origin that sends CORS headers |
controls | boolean | true | show the rotate buttons |
label | string | "Crop area" | |
labels | Partial<{ size: (width: number, height: number, x: number, y: number) => string; hint: string; rotateLeft: string; rotateRight: string; loadError: string; }> | — | the crop readout said after a keystroke, the hint under the image and the rotate buttons |
modelValue | BlessCropRect | null | null |
Events
| Name | Payload | Description |
|---|---|---|
update:modelValue | [value: BlessCropRect | null] | |
error | [] | |
ready | [] |
Exposed
| Name | Type | Description |
|---|---|---|
toBlob | (o?: { type?: string | undefined; quality?: number | undefined; maxWidth?: number | undefined; }) => Promise<Blob | null> | |
rotate | (d: 90 | -90) => 0 | 90 | 270 | 180 | |
reset | () => CropBox |