Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

ImageCropper

image-cropper

Lets users pan, pinch, zoom, and crop an image to a fixed ratio before Blob export.

Usage

ID photo 5:7

The default aspect ratio is 5:7 (the same ratio as the 1/2-inch ID photo). Drag and drop for alignment and slider scaling. After confirmation, the target size Blob is output. The storage/uploading is taken over by the consumer.

tsx
<ImageCropper
  image={objectUrl}
  aspect={5 / 7}
  maxBytes={200 * 1024}
  onCropped={(blob) => /* Storage / Upload */}
  onCancel={() => /* Close */}
/>

Square 1:1

aspect=1 is suitable for avatars; outputWidth controls the side length of the image.

tsx
<ImageCropper
  image={objectUrl}
  aspect={1}
  outputWidth={320}
  onCropped={(blob) => upload(blob)}
/>

Increase scaling limit

maxZoom Zoom in to crop a closer part; the slider range changes accordingly.

tsx
<ImageCropper image={objectUrl} aspect={1} maxZoom={5} onCropped={save} />

When to use

Use ImageCropper for avatars, ID photos, or covers that must be cropped to a fixed ratio and constrained before upload. Given an image and ratio, it lets the user pan and zoom, then returns a target-size Blob through onCropped. It commonly follows Upload: convert the selected File to an object URL and pass it to image.

Import

ts
import { ImageCropper, cropImageToBlob } from "@hulianui/ui"

Props

NameTypeDefaultDescription
image*string-Image source: object URL / data URL / origin address
aspectnumber5/7Cropping frame aspect ratio (identity photo 1 inch/2 inches same ratio)
outputWidthnumber413The output bitmap width (px), the height is rounded according to the aspect derivation (2 inches @300DPI)
outputTypestring"image/jpeg"output mime
qualitynumber0.9Encoding quality 0-1
maxBytesnumber-Upper limit of output bytes (such as 200*1024): If the limit is exceeded, the quality will be reduced and try again.
maxZoomnumber3Maximum zoom factor
cropAreaClassNamestringh-64 sm:h-80Cropping canvas area height class
classNamestring-Container class name

Events

EventTypeDescription
onCropped*(blob: Blob) => voidConfirm Cropping: Output Target Size Blob
onCancel() => voidCancel button click (if not passed, the cancel button will not be rendered)
onError(error: unknown) => voidCanvas export failed (extremely old browsers/canvas limited)

Slots

SlotTypeDescription
confirmLabelReactNodeConfirm button copy (default "confirm")
cancelLabelReactNodeCancel button copy (default "Cancel")

Usage guidelines

  • image must be readable by Canvas through same-origin, object, or data URLs. Cross-origin images without CORS headers taint the canvas and make export fail through onError.
  • maxBytes is best-effort. If the first export exceeds the limit, quality is reduced once (quality×0.72, minimum 0.5). The second result is returned even if it still exceeds the limit.
  • If onCancel is not passed, the cancel button will not be rendered (single action scene).

Related

SecretField · Combobox · Listbox · Mentions · InputOTP · Rating

Playground

<ImageCropper
  image={objectUrl}
  aspect={5/7}
  maxZoom={3}
  maxBytes={200 * 1024}
  onCropped={(blob) => /* Storage/Upload */}
  onCancel={() => /* Close */}
/>
PreviousRegionSelectFormsNextScopeMatrix

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Usage guidelines
    • Related
  • Playground