Show · Cropper
Cropper
Freely crop pictures

When to use

Cropper is used to crop pictures. It supports custom cropping box styles. The positions of the cropping box, cropped image can be adjusted by dragging. It can zoom and rotate the cropped pictures.

Demos

Cropper is supported starting from version v2.73.0.

Basic usage

Use sr to set the cropped image; use shape to set the shape of the cropping box, which defaults to square.

Customize crop box ratio

The initial crop box ratio can be passed through defaultAspectRatio (default is 1). A fixed crop box ratio can be set via aspectRatio.
Setting defaultAspectRatio only takes effect on the initial crop box ratio. When dragging, the crop box ratio will change with dragging.
When setting aspectRatio, the crop box ratio is fixed, and the crop box will change according to this ratio when dragging.

Controlled rotation/zooming of images

Control image rotation and zoom through rotate and zoom, and get the latest zoom value through onZoomChange

Crop box settings

The crop box style can be customized through cropperBoxStyle, cropperBoxClassName. You can use showResizeBox to set whether to display the adjustment blocks at the corners of the crop box.

API

PROPERTIESINSTRUCTIONSTYPEDEFAULT
aspectRatioCrop box width to height rationumber-
classNameclassNamestring-
cropperBoxClassNameThe class name passed to the crop boxstring-
cropperBoxStyleThe style passed to the crop boxCSSProperties-
defaultAspectRatioInitial crop box rationumber1
imgPropsAttributes passed through to the img tagobject-
fillThe fill color of the non-picture parts in the cropped resultstring'rgba(0, 0, 0, 0)'
maxZoomMaximum zoom factornumber3
minZoomMinimum zoom factornumber0.1
onZoomChangeCallback during zoom transformation(zoom: number) => void-
rotaterotation anglenumber-
shapeCrop box shape'rect' | 'round' | 'roundRect''rect'
srcThe address of the cropped imagestring-
showResizeBoxWhether to display the adjustment block of the cropping boxbooleantrue
styleStyleCSSProperties-
zoomZoom valuenumber-
zoomStepZoom step sizenumber0.1

Methods

Methods bound to component instances can be called through ref to achieve certain special interactions
NameDescription
getCropperCanvasGet the canvas of the cropped image

Design Token