ValyroUI Русская версия

Image Cropper

Image cropping: pan, zoom, rotate, aspect ratios and a round avatar. Pro · Forms and input › Files and images

Crop an image to a fixed aspect: pan by dragging (or arrow keys), zoom with the slider, wheel, pinch or +/-, rotate in 90° steps. Reports the crop area for getCroppedBlob.

Installation

npx valyro-cli@latest login
npx valyro-cli@latest add image-cropper
npm install valyro-ui-pro

import 'valyro-ui-pro/styles.css';
import { ImageCropper } from 'valyro-ui-pro';

Props

PropTypeDefault
srcstring | nullImage URL (an object URL or data URL works without CORS). Nothing is shown while empty.
altstring''Alt text of the image being cropped; empty marks it decorative.
aspectnumber1Width / height of the crop (default 1).
shape'rect' | 'circle''rect'circle for avatars: the crop is still a square area; mask the result with getCroppedBlob(…, { shape: 'circle' }).
zoomnumberControlled zoom; use with onZoomChange.
defaultZoomnumber1Initial zoom when uncontrolled.
onZoomChange(zoom: number) => voidCalled with the new zoom when it changes.
minZoomnumber1Lowest zoom of the slider, wheel and pinch; 1 is the image just covering the crop frame.
maxZoomnumber4Highest zoom of the slider, wheel and pinch, relative to the image just covering the crop frame.
rotationnumberDegrees, clockwise.
defaultRotationnumber0Initial rotation when uncontrolled.
onRotationChange(rotation: number) => voidCalled with the new rotation when it changes.
gridboolean | 'interaction''interaction'Rule-of-thirds grid: always, never, or while moving the image (default).
heightnumber | string320Height of the crop stage (default 320px).
controlsbooleantrueZoom slider and rotate button under the image (default true).
onCropChange(area: CropArea, percent: CropArea) => voidEvery change of the crop, while it happens.
onCropComplete(area: CropArea, percent: CropArea) => voidThe crop after an interaction ends (and once the image loads): area in px of the rotated image, and in percent.
labelsPartial<ImageCropperLabels>Overrides for the built-in English text; keys left out keep their defaults.

Related components

Previous: File Uploader · Next: Form Field · All Forms and input