Krizaka
Documentation

Image cropper

A fixed frame — square, round, 9:16, a banner — over a picture or a video the person drags and zooms; a focus point and a zoom out, cropRect for the pixels.

WebBetaMedia

Web only — React, from @krizaka/ui/image-cropper. Beta: its API may still change in a minor version.

When to use

  • To frame a profile picture or a cover before sending it.
  • To choose what a vertical (9:16) or square version of a landscape video keeps.

When not to use

  • To cut a video in time (not in space): the video trimmer.Use instead: Video trimmer
  • To send a file as it is: the file upload.Use instead: File upload

Installation

Install

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { ImageCropper, cropRect } from "@krizaka/ui/image-cropper";

Examples

Profile picture

A round mask on a square frame.

Drag or use the arrow keys to move the picture, + and − to zoom.

Banner

A 3:1 frame for a profile's cover, zoomed in.

Drag or use the arrow keys to move the picture, + and − to zoom.

Vertical version of a video

A <video> as the media, a 9:16 frame: choose what the vertical cut keeps.

Drag or use the arrow keys to move the picture, + and − to zoom.

Props

Chooses what a fixed frame keeps of a picture or a video: drag, zoom, keyboard; a focus point and a zoom out.

PropTypeDefaultDescription
aspectrequirednumber—The frame's width / height: 1 (a square), 9 / 16 (vertical), 3 (a banner).
altstring—The picture's alternative text, passed translated (empty when the frame's name says enough).
childrenReactElement<{ className?: string; style?: CSSProperties; }, string | JSXElementConstructor<any>> | undefined—A media element instead of src — a <video> to choose the frame of a clip. Its natural size is in naturalSize.
classNamestring—Classes merged on the root.
defaultValueCropValue{ x: 0.5, y: 0.5, zoom: 1 }The crop at first, uncontrolled. Default: centred, no zoom.
labelsPartial<ImageCropperLabels>—The words, passed translated; English by default.
maxZoomnumber4The largest zoom. Default 4.
naturalSize{ width: number; height: number; }—The source's size when children is a video: { width: video.videoWidth, height: video.videoHeight }.
onValueChange((value: CropValue) => void)—Called on every move.
roundboolean—A round mask over the square frame (a profile picture).
showZoombooleantrueShows the zoom slider under the frame. Default true.
srcstring—The picture to crop. Or children: a <video> (with the class it is given through mediaClassName).
valueCropValue—The crop (controlled).

Accessibility

  • The frame is a focusable group named by labels.frame and described by labels.instructions.
  • The zoom is a slider read as a percentage.
  • Nothing moves but what the person moves.

Keyboard

KeysAction
Arrow keysMove the picture in the frame (Shift: faster).
+ / −Zoom in or out.

Best practices

  • Store the focus point and the zoom (screen-independent), and crop on the server with cropRect.
  • Use round for an avatar: the person sees what others will see.
  • Keep the zoom slider (showZoom): pinch and Ctrl + wheel are not obvious to everyone.

Generated from the code of @krizaka/ui 2.4.0: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page