Skip to navigation

Introduction

zriz is a headless image cropper for React and Next.js, written in TypeScript. It crops avatars, profile pictures and cover photos with a straighten dial, pinch zoom and touch gestures, like the crop tool in iOS Photos.

Open
Download
0.0

Set it up with an agent

Paste this prompt into Claude Code, Cursor or any other coding agent. It reads quick start and adds a working cropper to your project:

Add zriz to this project. Read https://zriz.dev/docs/quick-start.md and follow it: install @zriz/react and @zriz/core, import its stylesheet and render a cropper with corner handles, the straighten dial and a file picker for the photo. Build it from the zriz parts, not a crop box of your own, and give every part that asks for one an aria-label. When it works, show me where onValueCommit hands back the crop.

What it does

FeatureWhat you get
StraightenA dial turns the photo up to 45° each way and glides on after a flick. The photo zooms in by the least amount that keeps every corner of the crop filled
Move and zoomDrag, pinch, trackpad and wheel. Pull past an edge and the photo stretches, then springs back when you let go
Rotate and flipAnimated quarter turns and mirroring, and a reset that undoes every change
Aspect ratioFree, the photo's own ratio or any ratio you name, with a portrait and landscape swap
Circle cropA round mask for avatars, exported as a PNG with transparent corners
ExportA file made off the main thread, or a plan your server uses to cut the original with sharp
AccessibilityKeys for the crop area, dial, zoom and aspect ratio, labels and announcements in your own words, and shorter motion when the system asks
StylingAn optional stylesheet, CSS variables, a data attribute for every state, dark mode and Tailwind
Plain dataThe crop is a small object you can save, restore, undo or send
Without ReactThe same core binds to plain elements, so it runs in any framework

Build it from parts

Import the parts as one namespace from @zriz/react/cropper, and the hooks from @zriz/react. These pages call the parts by their short names, such as Root.

Each part renders one outer element, which takes your props, className and ref. Image, Mask and Area go inside Viewport. The dial, zoom and buttons can sit anywhere inside Root, so your layout decides where they go:

<Cropper.Root src={photo} onValueCommit={save}>
  <Cropper.Viewport style={{ maxWidth: 400, height: 300 }}>
    <Cropper.Image />
    <Cropper.Mask />
    <Cropper.Area aria-label="Crop area" />
  </Cropper.Viewport>
  <Cropper.DialValue />
  <Cropper.Dial aria-label="Straighten">
    <Cropper.DialTicks />
  </Cropper.Dial>
</Cropper.Root>

onValueCommit hands you the crop each time a change ends.

The demo above runs this code. It adds handles, a grid, rotate, flip and reset, shows the angle to one decimal and uses the styles from the zriz site.