photocn

Search

Search the docs

3

API Reference

The useImageEditor hook that every component is built on.

import {
  ImageEditorProvider, // creates the editor, or shares one you pass in
  useImageEditor,      // reads the nearest provider
  useImageEditorState, // creates an editor without a provider
} from "photocn/react";

Options

useImageEditorState, <ImageEditorProvider> and <ImageEditor> all take these options.

OptionTypeDescription
srcstring | File | Blob | ArrayBuffer | HTMLImageElementThe image to edit.
defaultParamsEditorParamsEdits to start with, e.g. a saved session. Older formats are converted.
onParamsChange(params) => voidCalled after every edit.
tool / defaultTool / onToolChangestringThe active tool. Default "adjust".
onImageLoad / onImageError(result) / (error) => voidImage loading events.
onExport(result) => voidCalled after each export.
disabledbooleanTurn off all editing.
filterPresetsFilterPreset[]Replace the built-in filters.
aspectRatioOptions{ value, label }[]Crop ratio choices, e.g. { value: "3:2", label: "3:2" }.
renderMode"worker" | "main"Where rendering happens. Defaults to a worker when the browser supports it.
spawnWorker() => WorkerStart the render worker yourself, for strict CSPs.
keyboardShortcutsbooleanUndo/redo and crop shortcuts. Default true.
historyLimit / commitDelaynumberUndo depth (100), and how long (ms) a slider drag counts as one step (400).

What it returns

FieldDescription
status, isReady, isLoading, hasImage, errorLoading state.
params, setParams, patchThe current edits. patch(section, values, { transient }) groups slider drags into one undo step.
historyundo, redo, canUndo, canRedo.
tool, setToolThe active tool.
openFile(), load(src)Open a file picker, or load an image from code.
adjustLight, color and effects.
filterspresets, select(preset | label | null), setStrength(0..1).
curves, blur, blendEach tool's values and setters.
geometryCrop, straighten, perspective, rotate and flip. See Crop & transform.
compareactive, setActive: show the original.
recipescurrent (the look as JSON) and apply(recipe).
histogramdata and a canvasRef it draws into.
exportImage(options), download(options)Encode at full size, or at width/height. Options: format (png, jpeg, webp) and quality.
canvasRef, canvasKey, stageRef, rootRefAttach these to your canvas, its container and the editor's outer element. Use canvasKey as the canvas's key.
engine, workerLower-level access to the renderer and worker.

Custom filters

import { createLutPreset, filterPresets } from "photocn/filters";

// A 33×1089 3D LUT image, the same format as the built-in filters.
const presets = [...filterPresets, createLutPreset("teal-orange", "/luts/teal-orange.png")];

<ImageEditor src={src} filterPresets={presets} />;