Skip to content
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 aspect set (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 exposed rotate(90) / rotate(-90) do the same.
  • v-model is 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 to maxWidth. 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. ready fires when the image is in.

Usage ​

ts
import { BlessCropper } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
src*string—
aspectnumber—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
controlsbooleantrueshow the rotate buttons
labelstring"Crop area"
labelsPartial<{ 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
modelValueBlessCropRect | nullnull

Events

NamePayloadDescription
update:modelValue[value: BlessCropRect | null]
error[]
ready[]

Exposed

NameTypeDescription
toBlob(o?: { type?: string | undefined; quality?: number | undefined; maxWidth?: number | undefined; }) => Promise<Blob | null>
rotate(d: 90 | -90) => 0 | 90 | 270 | 180
reset() => CropBox

Released under the MIT License. Character names and artwork belong to their owners.