Installation
Add photocn to a React project that uses shadcn/ui.
1. Set up shadcn/ui
photocn is built on the Base UI version of shadcn/ui, the default for new projects:
npx shadcn@latest init -b base
Already have a project? Check that the style in your components.json starts with base- (for example base-nova).
2. Add the editor
pnpm dlx shadcn@latest add @photocn/image-editor@photocn is listed in the shadcn registry directory, so the CLI finds it with no setup.
This installs the photocn package, the shadcn/ui components the editor needs, and the editor files in components/image-editor/.
3. Use it
import { ImageEditor } from "@/components/image-editor/image-editor";
export default function Page() {
return <ImageEditor className="h-dvh" src="/photo.jpg" />;
}
The editor is a client component. src can be a URL, a File, a Blob, an ArrayBuffer or an <img>. Images from other domains need CORS headers.
Only need some pieces?
Every piece can be installed on its own:
pnpm dlx shadcn@latest add @photocn/image-editor-canvas @photocn/image-editor-filters @photocn/image-editor-exportContent-Security-Policy
The renderer runs in a Web Worker started from a blob: URL, so no bundler setup is needed. If your CSP blocks worker-src blob:, start the worker yourself:
<ImageEditor
src={src}
spawnWorker={() =>
new Worker(new URL("photocn/worker/entry", import.meta.url), { type: "module" })
}
/>