Skip to content
OTF Kit logoOTF Kit

Image Crop

Display

Drag-to-crop image utility with optional aspect-ratio lock, circular mask, and canvas export.

View in Storybook
Image Crop
Loading Storybook preview…

Installation

bun add @otfdashkit/ui

Usage

Import Image Crop from @otfdashkit/ui.

Code
// Image Crop — Drag-to-crop image utility with optional aspect-ratio lock, circular mask, and canvas export.
//
// Install:
//   bun add @otfdashkit/ui

import { ImageCrop } from '@otfdashkit/ui'

export function Example() {
  return (
    <ImageCrop>
      {/* your content */}
    </ImageCrop>
  )
}

Props

Props declared in the ImageCrop source. Inherited HTML attributes are not listed.

PropTypeDefaultDescription
srcrequiredstringImage URL — required.
altstring'Crop source'Alt text for the source image.
aspectnumberOptional aspect-ratio lock, e.g. 16/9, 1, 4/3.
circularbooleanfalseRender a circular crop mask (for avatars). Default false.
defaultCrop{ x: number; y: number; width: number; height: number; }Initial crop in % values.
minHeightnumberMinimum crop height in pixels.
minWidthnumberMinimum crop width in pixels.
onComplete(result: { croppedSrc: string; crop: PixelCrop; }) => voidFired (debounced) after a drag with the cropped data URL + pixel crop.
outputFormat'png' | 'jpeg' | 'webp''png'Output image format. Default 'png'.
outputQualitynumber0.92Output image quality 0..1 (jpeg/webp only). Default 0.92.

Related