Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Image Cropper for React and Tailwind

Crop and transform images.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/image-cropper.json

Anatomy

ImageCropper
├── ImageCropperImage
├── ImageCropperSelection
├── ImageCropperHandle
└── ImageCropperGrid

Usage

import {
  ImageCropper,
  ImageCropperImage,
  ImageCropperSelection,
} from "@/components/ui/image-cropper";
<ImageCropper>
  <ImageCropperImage alt="Crop me" src="/image.jpg" />
  <ImageCropperSelection />
</ImageCropper>

Examples

Aspect ratio

Use the aspectRatio to lock the crop area to a specific aspect ratio.

Circle crop

Use cropShape="circle" for profile pictures or avatars.

Initial crop

Start with a pre-defined crop area using the initialCrop prop.

Controlled zoom

Control zoom programmatically with the zoom and onZoomChange props.

Zoom limits

Set minZoom and maxZoom to constrain how far users can zoom.

Min and max size

Constrain the crop area size with minWidth, minHeight, maxWidth, and maxHeight.

Fixed crop area

Set fixedCropArea to true when the crop area should stay fixed while the image moves underneath.

API Reference

ImageCropper

Root wrapper. Manages crop state and handles.

PropTypeDefault
aspectRationumber-
cropShape"circle" | "rectangle""rectangle"
fixedCropAreabooleanfalse
initialCrop{ x: number; y: number; width: number; height: number }-
maxHeightnumberInfinity
maxWidthnumberInfinity
maxZoomnumber5
minHeightnumber40
minWidthnumber40
minZoomnumber1
onCropChange(details: CropChangeDetails) => void-
onZoomChange(details: ZoomChangeDetails) => void-
rotationnumber-
zoomnumber-
classNamestring-
AttributeDefault
--cropper-accentvar(--color-white)
--cropper-handler-size--spacing(2)
--cropper-handler-width--spacing(1)

ImageCropperImage

Image to crop. Pass src and alt.

PropTypeDefault
altstring-
srcstring-
classNamestring-

ImageCropperSelection

Crop selection overlay with resize handles and optional grid.

PropTypeDefault
axis"horizontal" | "vertical" | "both""both"
classNamestring-

For a complete list of props, see the Ark UI documentation.