Web · Components
MediaEditor
Image and video editor: full screen and dark like WhatsApp, made for finger use.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
FileUpload + edit: pick, edit, add (like WhatsApp)
Profile photo: square, circular crop, crop + adjust only
Import
Image and video editor: full screen and dark like WhatsApp, made for finger use.
- Image: crop (free, original, preset ratios or a fixed ratio; a circle for profiles), 90° rotation, mirroring, drawing with a pen and highlighter, a blur (pixelate) brush, draggable text (plain or boxed), preset looks and brightness/contrast/saturation/warmth adjustments.
- Video: range selection with two handles on a frame strip (duration limit with
maxDuration), mute, play/pause; all image tools (crop, rotate, draw, text, blur, color) apply to video too. - Multiple: with several items a thumbnail strip at the bottom; each item has its own edits and undo history. Edited ones are marked.
- Non-destructive editing: edits are kept as
MediaEditsand returned with the original file in the result; you can continue later from the same point. A file with no changes isn't reprocessed (no quality loss). - Performance: the on-screen preview uses a downscaled copy and color adjustment is drawn on the GPU (CSS filter); full resolution is processed only on "Done". Video is processed with the browser's own encoder (MP4 or WebM); processing can be cancelled.
- Keyboard: Ctrl/⌘+Z undo, Ctrl/⌘+Shift+Z redo; the crop area and texts move with the arrow keys, Delete removes a text; trim handles move with the arrow keys (1 s with Shift).
- Mobile: the phone's back button closes it; a text is deleted by dragging it to the trash; tools are at the bottom within thumb reach.
It is very small while closed; the actual editor is loaded on demand as a separate chunk when used via edit in FileUpload.
Examples
mediaFilterPresets
constantBuilt-in looks. Their names are written to MediaAdjustments.preset; the on-screen names come from the preset_<name> keys in the mediaEditor texts.
hasMediaEdits
functionWhether the edits change the appearance; if not, the file isn't reprocessed (no quality loss and no waiting).
defaultMediaEditorMessages
constantTurkish texts of MediaEditor.
renderImage
functionApplies edits to an image and produces a new file. The editor calls it itself on "Done"; it can also be used directly in your own flow (e.g. to apply stored edits before sending to the server).
Examples
canRenderVideo
functionCan the browser reprocess the video (MediaRecorder and canvas.captureStream)? If not, the editor returns the original file and the edits.
renderVideo
functionApplies edits (trim, mute, crop, rotate, color, drawing, text) to a video and produces a new file. Works in real time with the browser's own encoder (MediaRecorder): a 10-second clip takes about 10 seconds. The output is MP4 (H.264/AAC) if supported, otherwise WebM.
If the tab goes to the background the browser may slow down frames; the page should stay open while processing.
Examples
Built-in look name.
MediaEditorItem
interfaceFile given to the editor: a File or an object with a URL/edit info.
| Name | Type | Description |
|---|---|---|
id? | string | Unique key; returned as is in the result. If omitted, the index. |
file? | Blob | File to edit. If missing, it is downloaded from url. |
url? | string | URL of a file on the server (if there is no file). It must be same-origin or CORS-enabled so it can be drawn on a canvas. |
name? | string | File name. |
type? | string | MIME type; the kind (image/video) is chosen by it. |
edits? | MediaEdits | Previous edits; the editor opens with them and they can be undone. |
MediaEditorResult
interfaceResult the editor returns for a file.
| Name | Type | Description |
|---|---|---|
id | string | The item's id (the index if not given). |
kind | MediaKind | Image or video. |
file | File | Result file: the new file if edited, the original if not. For video, it is the original if output.video.render is false or the browser can't process it; the edits are in edits. |
original | File | Original file; store it with edits to re-edit. |
edits | MediaEdits | Applied edits (an empty object: no edits). |
edited | boolean | Did the look change? |
rendered | boolean | Does file include the edits? (false: the server should apply them.) |
MediaEditorProps
interfaceProps of the MediaEditor component.
| Name | Type | Default | Description |
|---|---|---|---|
open | boolean | Is it open? Nothing renders while closed, and the state resets. | |
onOpenChange | (open: boolean) => void | Called when the open state wants to change (close, cancel, done). | |
items | readonly (File | MediaEditorItem)[] | Images and videos to edit. With one item the single view opens, with several the multi view with a thumbnail strip at the bottom. Files other than images and videos are ignored. Changes while open are not taken into account. | |
tools? | MediaEditorTools | Which tools are enabled. See MediaEditorTools. | |
output? | MediaEditorOutput | Output settings (type, quality, size, video processing). See MediaEditorOutput. | |
onDone | (results: MediaEditorResult[]) => unknown | Called when "Done" is pressed, after the files are processed. If it returns a Promise, the editor stays open until it settles. | |
onCancel? | () => void | Called when the user cancels editing. | |
removable? | boolean | true | In the multi view files can be removed from the strip (removed ones are not in the result). |
doneLabel? | ReactNode | a check icon | Content of the Done button. |
defaultIndex? | number | 0 | Index of the item opened first. |
confirmDiscard? | boolean | true | Ask when closing with unsaved changes? |
messages? | Partial<MediaEditorMessages> | Texts. See MediaEditorMessages. | |
className? | string | Classes added to the window. |
MediaEditorMessages
interfaceMediaEditor texts. Placeholders like {name} are filled in. Changed app-wide in the dictionary's ui.mediaEditor namespace, or for one editor with the messages prop.
| Name | Type | Description |
|---|---|---|
title | string | Screen reader name of the window. |
close | string | Close button. |
done | string | Done button. |
undo | string | Undo. |
redo | string | Redo. |
crop | string | Crop tool. |
draw | string | Draw tool. |
blur | string | Blur tool. |
text | string | Text tool. |
adjust | string | Color adjustment tool. |
mute | string | Mute the video's audio. |
unmute | string | Unmute the video. |
cropArea | string | Crop area (moved with arrow keys). |
rotate | string | Rotate left. |
flip | string | Mirror. |
reset | string | Reset the tool's edits. |
aspectFree | string | Free crop ratio. |
aspectOriginal | string | Original crop ratio. |
pen | string | Pen brush. |
marker | string | Highlighter brush. |
size | string | Brush size. |
color | string | Color selection. |
textPlaceholder | string | Placeholder of the text box. |
textSize | string | Text size slider. |
textStyle | string | Button that changes the text style. |
deleteText | string | Text delete zone. |
textHandle | string | Move hint for text (screen reader): {text}. |
presets | string | Built-in looks tab. |
adjustments | string | Settings tab. |
brightness | string | Brightness. |
contrast | string | Contrast. |
saturation | string | Saturation. |
warmth | string | Warmth. |
preset | { /** Original. */ none: string; /** Vivid. */ vivid: string; /** Warm. */ warm: string; /** Cool. */ cool: string; /** Faded. */ fade: string; /** Dramatik. */ drama: string; /** Black and white. */ mono: string; /** Noir. */ noir: string; /** Sepya. */ sepia: string; } | Built-in look names (by mediaFilterPresets keys). |
play | string | Play. |
pause | string | Pause. |
trimStart | string | Trim start handle. |
trimEnd | string | Trim end handle. |
maxDuration | string | Maximum trimmed duration: {duration}. |
itemOf | string | Name of the file in the queue: {index}, {count}. |
remove | string | Remove the file from the list: {name}. |
edited | string | Screen reader state of an edited file. |
items | string | Name of the file strip. |
processing | string | While processing. |
processingOf | string | Processing percentage: {index}, {count}, {percent}. |
cancel | string | Cancel processing. |
discardTitle | string | Question when closing with unsaved changes. |
discardDescription | string | Description of the close question. |
discard | string | Discard changes and close. |
loadError | string | The file could not be opened. |
renderError | string | The file could not be processed. |
MediaRect
interfaceRectangle given as fractions (0 – 1) of the source. Regardless of rotation and mirroring it is always in the coordinates of the original image/video, so it shows the same region even when rotated later.
| Name | Type | Description |
|---|---|---|
x | number | Left edge (0 – 1). |
y | number | Top edge (0 – 1). |
width | number | Width (0 – 1). |
height | number | Height (0 – 1). |
MediaRotation
typeClockwise rotation angle.
MediaBrush
typeBrush kind.
pen: plain pen.marker: semi-transparent, thick highlighter.blur: pixelates where it passes (to hide faces, plates, addresses).
MediaStroke
interfaceA brush stroke. Points are fractions of the original source.
| Name | Type | Description |
|---|---|---|
brush | MediaBrush | Brush. See MediaBrush. |
color | string | Color (CSS color); not used for blur. |
size | number | Thickness: fraction of the source's short edge (e.g. 0.01). |
points | number[] | Points in order [x0, y0, x1, y1, …] (0 – 1). |
MediaTextStyle
typeText style.
plain: plain text with a shadow.box: text inside a colored box (text color black or white depending on the box).
MediaText
interfaceText added over the image.
| Name | Type | Description |
|---|---|---|
id | string | Unique key. |
text | string | Text; lines are separated with \n. |
x | number | Center of the text: fractions of the original source (0 – 1). |
y | number | Center of the text (vertical). |
size | number | Font size: fraction of the source's short edge (e.g. 0.06). |
color | string | Color (CSS color). |
style | MediaTextStyle | Style. See MediaTextStyle. |
MediaAdjustments
interfaceColor adjustments. Each is between -1 and 1 around 0 (unchanged); preset picks a built-in look and the adjustments are added on top.
| Name | Type | Description |
|---|---|---|
preset? | string | undefined | Built-in look name (e.g. "vivid"). See mediaFilterPresets. |
brightness? | number | undefined | Brightness. |
contrast? | number | undefined | Contrast. |
saturation? | number | undefined | Saturation. |
warmth? | number | undefined | Warmth: negative is cool (blue), positive warm (yellow). |
MediaEdits
interfaceEdits of an image or video. Stored non-destructively (the original file is untouched); the same edits can be reopened and changed later, or applied on the server. An empty object means no edits.
| Name | Type | Default | Description |
|---|---|---|---|
rotation? | MediaRotation | undefined | 0 | Clockwise rotation. |
flip? | boolean | undefined | Horizontal mirroring (after rotation). | |
crop? | MediaRect | undefined | Cropped region (relative to the original source). Everything when absent. | |
adjust? | MediaAdjustments | undefined | Color adjustments. | |
strokes? | readonly MediaStroke[] | undefined | Drawings (in the order added). | |
texts? | readonly MediaText[] | undefined | Texts. | |
trim? | { start: number; end: number; } | undefined | Trimmed range of a video (seconds). | |
muted? | boolean | undefined | The video is muted. |
MediaKind
typeMedia type.
MediaAspectRatio
typeCrop ratio option: a number (width / height), "original" (the original ratio) or "free".
MediaCropOptions
interfaceCrop tool options.
| Name | Type | Default | Description |
|---|---|---|---|
aspectRatio? | number | Fixed ratio (e.g. 1 for a profile picture). When given, the user can't change the ratio and the editor center-crops to it on open. | |
aspectRatios? | readonly MediaAspectRatio[] | ["free", "original", 1, 4 / 5, 16 / 9] | Ratios the user can choose. |
shape? | "rect" | "circle" | Show the crop area as a circle (profile picture). The output is still square. | |
rotate? | boolean | true | Rotate and mirror buttons. |
MediaTrimOptions
interfaceVideo trim tool options.
| Name | Type | Default | Description |
|---|---|---|---|
maxDuration? | number | Maximum duration (seconds). Longer videos are trimmed to it on open. | |
minDuration? | number | 0.5 | Minimum duration (seconds). |
MediaImageTools
interfaceTools available for images. Each is true (default) or false; crop can also take an options object.
| Name | Type | Description |
|---|---|---|
crop? | boolean | MediaCropOptions | Crop, rotate, mirror. See MediaCropOptions. |
draw? | boolean | Pen drawing. |
blur? | boolean | Blur (pixelate) brush. |
text? | boolean | Adding text. |
adjust? | boolean | Built-in looks and brightness/contrast/saturation/warmth. |
MediaVideoTools
interfaceTools available for videos; trim and sound in addition to the image tools.
Extends: MediaImageTools
| Name | Type | Description |
|---|---|---|
trim? | boolean | MediaTrimOptions | Trimming by selecting a range. See MediaTrimOptions. |
mute? | boolean | Mute button. |
MediaEditorTools
interfaceWhich tools are enabled for which type. true enables all tools, false means that type isn't edited; an object picks tool by tool.
| Name | Type | Default | Description |
|---|---|---|---|
image? | boolean | MediaImageTools | true | Image tools. |
video? | boolean | MediaVideoTools | true | Video tools. |
Examples
MediaImageOutput
interfaceImage output options.
| Name | Type | Default | Description |
|---|---|---|---|
type? | "auto" | "image/jpeg" | "image/png" | "image/webp" | "auto" | File type. "auto" keeps the original type (JPEG, PNG, WebP) and makes everything else JPEG. |
quality? | number | 0.92 | JPEG/WebP quality (0 – 1). |
maxSize? | number | 4096 | Maximum size of the long edge (pixels); larger images are downscaled. |
MediaVideoOutput
interfaceVideo output options.
| Name | Type | Default | Description |
|---|---|---|---|
render? | boolean | true | Render the edits into a new video in the browser? Rendering is real time (a 10 s clip takes ≈ 10 s). With false the original file and edits are returned and the server applies the edits (e.g. ffmpeg). |
maxSize? | number | 1920 | Maximum size of the long edge (pixels). |
bitrate? | number | Bitrate (bits/s). Chosen from the resolution when omitted. | |
frameRate? | number | 30 | Frame rate. |
MediaEditorOutput
interfaceOutput options for edited files.
| Name | Type | Description |
|---|---|---|
image? | MediaImageOutput | Images. See MediaImageOutput. |
video? | MediaVideoOutput | Videos. See MediaVideoOutput. |
RenderVideoOptions
interfacerenderVideo options.
Extends: MediaVideoOutput
| Name | Type | Description |
|---|---|---|
signal? | AbortSignal | Cancels the process; the promise rejects with AbortError. |
onProgress? | (progress: number) => void | Progress (0 – 1). |