Back to Shark UI

Image Cropper

docs/components/image-cropper

latest8.7 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Image Cropper

Copy Markdown

Crop and transform images.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/image-cropper

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.

PreviewCode

Circle crop#

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

PreviewCode

Initial crop#

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

PreviewCode

Controlled zoom#

Control zoom programmatically with the zoom and onZoomChange props.

PreviewCode

Zoom limits#

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

PreviewCode

Min and max size#

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

PreviewCode

Fixed crop area#

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

PreviewCode

API Reference#

ImageCropper#

Root wrapper. Manages crop state and handles.

PropTypeDefault
aspectRationumber-
cropShape`"circle""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"
classNamestring-

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

[

Previous page

Hover Card ](/docs/components/hover-card)[

Next page

Input Group ](/docs/components/input-group)

On This Page

InstallationAnatomyUsageExamplesAspect ratioCircle cropInitial cropControlled zoomZoom limitsMin and max sizeFixed crop areaAPI ReferenceImageCropperImageCropperImageImageCropperSelection