Photocairn for developers and AI agents
Photocairn (https://photocairn.silicairn.com/) is a free, private photo editor that runs entirely in the browser: remove backgrounds with on-device AI, crop, resize, adjust, blur out details, add text, work with layers and convert formats. No ads, no account, no uploads. Besides the normal UI it has a small scripting API, window.photocairn, so AI agents and automation can edit images in the page.
This document covers what Photocairn does, every tool and its settings, the keyboard shortcuts, and the full window.photocairn API reference with examples. It's also available as plain text at llms-full.txt (short version: llms.txt). Source code: github.com/apopov04/photocairn (MIT).
Privacy
- Editing runs locally. Photos are decoded, edited and encoded in the browser tab. Nothing is uploaded: the page's Content-Security-Policy (
connect-src 'self') doesn't let it connect to any other server. There are no accounts, analytics, ads or cookies. - The AI models are local too. Background removal runs U²-Net models with ONNX Runtime (WebAssembly) in a Web Worker. The models are downloaded once from this same site and cached.
- But an AI agent can see what it works on. If an AI agent drives your browser (ChatGPT agent, Claude in Chrome, a Playwright script that calls a hosted model...), that agent sees the page, its screenshots and anything
getImage()orexport()returns, and it may send them to the service that runs its model. Photocairn can't prevent that. Only let an agent handle images you'd be happy to share with that service. - The API doesn't reach out on its own. It only fetches a URL when you pass one to
open()oraddLayer(), and only downloads a file when you callexport({ download: true }). Loading from other sites is blocked by the security policy anyway.
Quick start for agents
- Open https://photocairn.silicairn.com/ in the browser.
window.photocairnis ready once the page has loaded (it also fires aphotocairn:readyevent onwindow).- Run JavaScript in the page (DevTools console, Playwright's
page.evaluate, your agent's "run script" tool):
await photocairn.help(); // every method with its parameters, ranges and defaults
await photocairn.help("redact"); // one method
await photocairn.open(dataUrl); // a data: URL, Blob/File, or a URL on this site
await photocairn.adjust({ brightness: 15, warmth: 10 });
await photocairn.info(); // size, layers, selection, history
const preview = await photocairn.getImage({ format: "jpeg", maxSize: 768 }); // cheap look at the result
const png = await photocairn.export({ format: "png" }); // data URL of the final image
Conventions
photocairn.versionis the app version,photocairn.apiVersionis 1. New methods and options may be added in the same API version; anything that breaks existing calls would bump it.- Every method returns a Promise. Calls run one at a time, in the order they were made.
- Arguments are plain JSON-friendly objects. Most methods take one options object; a few also take their main argument directly:
rotate(90),flip("horizontal"),look("mono"),editText(1, { ... }). - Coordinates and sizes are image pixels, with (0, 0) at the top-left of the image, not screen pixels. If you located something on a downscaled
getImage({ maxSize })preview, scale its coordinates byinfo().width / previewWidth. - Colors are hex strings:
"#ff8800"or"#f80". Percentages (opacity, strength, quality) are 0 to 100. Adjustment sliders run from -100 to 100, as in the app. - Layers are numbered from the bottom: 0 is the bottom layer. Methods that take a
layeraccept that index or the layer's exact name. - Wrong arguments throw an
Errorthat says what was expected, e.g.crop() needs "y": ...oradjust() has no option "brightnes". With no image open you getNo image open. Call photocairn.open(source) or photocairn.newImage({ width, height }) first. - Every edit goes through the same code as the app's own tools: it acts on the active layer, stays inside the selection if there is one, refuses locked or hidden layers with a clear error, adds one named step to the History panel and can be undone with
photocairn.undo(). Crop, resize, rotate and flip change the whole image (all layers). - A person watching the tab sees every change happen in the normal UI and can undo it.
open()andnewImage()replace the current image without asking, unlike the app's own Open command. Export first if the current work matters.
Playwright
import { chromium } from "playwright";
import fs from "node:fs";
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto("https://photocairn.silicairn.com/");
await page.waitForFunction(() => window.photocairn);
const dataUrl = "data:image/jpeg;base64," + fs.readFileSync("photo.jpg").toString("base64");
await page.evaluate((u) => photocairn.open(u, { name: "photo.jpg" }), dataUrl);
await page.evaluate(() => photocairn.resize({ width: 1080 }));
const out = await page.evaluate(() => photocairn.export({ format: "webp", quality: 80 }));
fs.writeFileSync("photo.webp", Buffer.from(out.split(",")[1], "base64"));
await browser.close();
Example: remove a background and export
An agent cuts out the subject of a product photo, puts it on white and saves a square JPEG.
await photocairn.open(photoDataUrl, { name: "mug.jpg" });
// Downloads the 4.6 MB "fast" model on first use (cached afterwards), then runs it on this device.
await photocairn.removeBackground({
model: "fast", // or "best": 44 MB, cleaner edges
background: "#ffffff", // or "transparent" (default), any hex color, or "blur"
onProgress: (p) => console.log(p.stage, Math.round(p.progress * 100) + "%"),
});
// Check the result cheaply before saving.
const check = await photocairn.getImage({ format: "jpeg", maxSize: 512 });
// ...show `check` to the vision model; if an edge needs work: await photocairn.undo() and try model: "best".
const { width, height } = await photocairn.info();
const side = Math.min(width, height);
await photocairn.crop({ x: (width - side) / 2, y: (height - side) / 2, width: side, height: side });
const jpeg = await photocairn.export({ format: "jpeg", quality: 90 }); // data URL
// or let the browser save it:
await photocairn.export({ format: "jpeg", quality: 90, download: true, filename: "mug-white" });
For a transparent cutout, leave out background and export as PNG or WebP (JPEG has no transparency, so see-through areas would turn white).
Example: blur out part of a screenshot
An agent hides an email address and an API key in a screenshot before it's shared.
await photocairn.open(screenshotDataUrl, { name: "screenshot.png" });
const { width } = await photocairn.info();
// 1. Look at a small copy to find what to hide.
const small = await photocairn.getImage({ format: "jpeg", maxSize: 1024 });
// The vision model finds the email at (412, 96, 260 x 24) on the 1024 px copy.
const s = width / Math.min(1024, width); // preview pixels to image pixels (1 if not downscaled)
// 2. Blur the email. Blur and pixelation can sometimes be reversed...
await photocairn.redact({ x: 412 * s, y: 96 * s, width: 260 * s, height: 24 * s, mode: "blur", strength: 80 });
// 3. ...so cover secrets (passwords, keys, card numbers) with a solid box.
await photocairn.redact({ x: 180 * s, y: 540 * s, width: 520 * s, height: 30 * s, mode: "box", color: "#000000" });
// 4. Check, then export. Exports never contain metadata.
const after = await photocairn.getImage({ format: "jpeg", maxSize: 1024 });
const png = await photocairn.export({ format: "png" });
The History panel now shows Blur and Solid box steps; await photocairn.undo() reverts the last one.
Tools
The editor looks like a small Photoshop: a menu bar (File, Edit, Image, Layer, Select, Filter, View, Help), tools down the left, and on the right the active tool's options, then History, then Layers. On phones the tools move to the bottom and the panels share a tabbed sheet. Tools that share a toolbar button (brushes, selections, fills, shapes, blur out) have a small corner mark: right-click or long-press to pick another one, or press its key again to cycle. "API" names the matching window.photocairn method.
Files
- Open: PNG, JPG, WebP, AVIF, GIF and PSD (with layers); drag and drop, paste, or File › Open. Very large photos are scaled to 16.7 megapixels. Photos with a GPS location show a warning. API:
open(). - New blank image: width and height (1 to 8000 px), presets (1080 × 1080, 1080 × 1350, 1080 × 1920, 1920 × 1080, 1200 × 630, 512 × 512), background white, transparent or the main color. API:
newImage(). - Place image as layer (File menu, or drop/paste onto an open image): adds an image as a new layer, scaled to fit and centered. API:
addLayer({ image }). - Save / Export (Ctrl+S): format PNG, JPG, WebP or layered PSD; quality 10 to 100% (JPG/WebP); size 10 to 100%; file name; live file-size estimate; Download or Copy to clipboard. Location and camera data are never included. API:
export(). - Metadata: view & remove (File menu, or from the start screen): lists GPS, camera and lens serials, dates, author, maker notes, the embedded thumbnail, XMP, IPTC and more in a JPEG, PNG or WebP, and saves a cleaned copy without re-compressing it. No API.
Selecting and moving
- Move (V): drag the active layer, or only the selected pixels. Arrow keys nudge by 1 px (Shift: 10 px). Center on canvas. No API.
- Select (M, Shift+M cycles): Rectangle, Ellipse, Lasso, Polygon (click corners; click the first point, double-click or Enter to finish) and Magic wand (W; tolerance 0 to 100, default 12; contiguous; sample all layers). Mode: new, add, subtract, intersect (or hold Shift to add, Alt to subtract). Buttons: All, None, Invert, Crop, Copy → layer, Cut → layer, Fill, Delete. Brushes, fills, adjustments and filters then only change the selected area. API:
select(),selectColor(),selectAll(),deselect(),invertSelection(),cropToSelection(),fillSelection(),deleteSelection(). - Snap (View › Snap, Ctrl+Shift+;, on by default): Move and Free transform snap the content's edges and centre to the canvas edges and centre lines and to the edges and centres of other visible layers, with magenta guide lines. Hold Ctrl (Cmd on Mac) while dragging to move freely.
- Free transform (Ctrl+Alt+T): scale, rotate, flip and move a layer or selection with handles, or type width %, height % and angle. No API.
Image
- Crop (C): drag the frame; aspect ratio Free, Original, 1:1, 4:5, 3:2, 16:9 or 9:16; rotate 90° and flip buttons; Straighten -45° to 45°. Enter applies. API:
crop(). - Rotate & flip (Image menu): 90° steps, 180°, flip horizontal or vertical, or any angle from -180° to 180° (the canvas grows to fit), for the whole image or only the current layer. API:
rotate(),flip()(whole image only). - Image size: width and height in pixels, keep proportions, quick sizes 25/50/75% and longest side 1080/1920/512 px. API:
resize(). - Canvas size: add or trim space around the image without scaling; anchor; new area transparent, second color or main color. No API.
- Corners & border: rounded corners 0 to 100%, circle crop, border 0 to 30% with a color. No API.
Painting
- Brush tools (B, Shift+B cycles): Brush (size, hardness, opacity, main color), Pencil (N; hard pixel-exact lines), Pen (smoothed ink for writing and signatures), Highlighter (flat see-through chisel tip that darkens what's under it; own color, yellow by default). Shift+click draws a straight line, Alt+click picks a color, [ and ] change the size. API:
brushStroke(). - Eraser (E): Brush (soft, with hardness) or Block (square, pixel-exact); size and opacity. API:
brushStroke({ kind: "eraser" }). - Fill tools (G, Shift+G cycles): Paint bucket (K; tolerance 0 to 100, default 32; opacity; contiguous; sample all layers) and Gradient (linear or radial, from the main color to the second color or to transparent; opacity). API:
fill()(no gradient). - Eyedropper (I): sample 1 px, 3×3 or 5×5, from all layers or the current one. Alt+click sets the second color. No API.
- Spot healing (J): paint over a small blemish, dust spot, scratch or stray hair; when you let go it is filled with texture from around it. For small areas.
- Clone stamp (J again, or right-click the Healing button): Alt+click (or Pick source on touch) the spot to copy from, then paint to copy it. Aligned keeps the source moving with the brush.
- Shapes (U, Shift+U cycles): Line, Arrow, Rectangle and Ellipse; line width, opacity, filled (rectangle and ellipse). Shift keeps 45° angles or a perfect square or circle. API:
drawShape(). Each shape gets its own layer and stays editable: with the Shapes tool, drag its handles to resize, drag it to move, and change color, width, opacity or fill. Painting or filtering it turns it into pixels. - Text (T): click to add text or drag to draw a wrapping text box. Font (Sans, Serif, Bold, Mono, Casual), size, weight (Light to Black), alignment, text color, background color, italic and outline. Each text is an editable text layer: click it with the Text tool, or double-click it, to change it. Painting or filtering a text layer turns it into pixels. API:
addText(),editText(). Fonts: the built-in five, a library of 50 free fonts hosted on this site (including look-alikes for Arial, Times New Roman, Calibri, Cambria, Georgia, Garamond and Courier New), fonts installed on your computer (Chrome/Edge), or your own .ttf/.otf files. Fonts download only when used. - Colors: main and second color at the bottom of the toolbar. X swaps them, D resets to black and white.
Photo
- Remove background: finds the main subject and removes everything else with AI on this device. Model Fast (4.6 MB) or Best quality (44 MB). Afterwards: a transparent, colored or blurred background, and Erase/Restore brushes to touch up the edges. API:
removeBackground()(no touch-up brushes; usebrushStroke({ kind: "eraser" })to erase). - Adjust (Image › Adjustments): brightness, contrast, exposure, highlights, shadows, saturation, warmth and tint (-100 to 100), sharpen and soften (0 to 100). API:
adjust(). - Filters: Mono, Sepia, Invert, Vivid, Warm, Cool, Fade, Noir and Vintage, with a strength slider (0 to 100%). API:
look(). - Blur out: drag over faces, number plates, names or anything private. Blur and Pixelate (strength 10 to 100) or Solid box (a color). Use Solid box for passwords, card numbers and IDs: blur and pixelation can sometimes be reversed. API:
redact().
Layers and history
- Layers panel: new, add image, duplicate, move up/down, merge down, clear and delete; click to select, double-click to rename, eye to show or hide; opacity 0 to 100% and 16 blend modes (Normal, Multiply, Screen, Overlay, Darken, Lighten, Color dodge, Color burn, Hard light, Soft light, Difference, Exclusion, Hue, Saturation, Color, Luminosity); locks for transparent pixels, image pixels, position, or all. Layer menu: merge visible, flatten. API:
addLayer(),selectLayer(),setLayer(),duplicateLayer(),moveLayer(),deleteLayer(),mergeDown(),flatten(). - History panel: one row per step (Brush, Fill, Merge down...), starting with the opened image. Click a step to go back to it, or a dimmed later step to redo up to it. About 400 MB of image data is kept; the oldest steps are dropped first. API:
undo(),redo(),info().history. - Compare: hold the compare button (or
\) to see the original photo.
Keyboard shortcuts
| Action | Keys |
|---|---|
| Move / Select / Crop | V / M / C |
| Next selection tool (Ellipse, Lasso, Polygon, Magic wand) | M again / Shift+M |
| Magic wand | W |
| Brush tools / Pencil / Eraser | B / N / E |
| Next brush tool (Pencil, Pen, Highlighter) | B again / Shift+B |
| Fill tools / Paint bucket | G / K |
| Next fill tool (Paint bucket, Gradient) | G again / Shift+G |
| Eyedropper | I |
| Shapes / Text | U / T |
| Next shape (Line, Arrow, Rectangle, Ellipse) | U again / Shift+U |
| Free transform | Ctrl+Alt+T |
| Snap on / off | Ctrl+Shift+; |
| Swap / reset colors | X / D |
| Brush or text size | [ / ] |
| Select all / Deselect / Invert selection | Ctrl+A / Ctrl+D / Ctrl+Shift+I |
| Copy / Cut / Paste | Ctrl+C / Ctrl+X / Ctrl+V |
| Selection to new layer | Ctrl+J |
| New layer / Merge down | Ctrl+Shift+N / Ctrl+E |
| Delete selected pixels | Delete |
| Undo / Redo | Ctrl+Z / Ctrl+Shift+Z or Ctrl+Y |
| Open / Save | Ctrl+O / Ctrl+S |
| Zoom in / out, Fit, 100% | + / −, 0, 1 |
| Pan | hold Space |
| Compare with the original | hold \ |
| Layers panel | L |
| Apply (crop, transform) / Cancel or deselect | Enter / Esc |
On a Mac, use Cmd instead of Ctrl.
API reference
All methods live on window.photocairn and return Promises. "History" names the step each call adds to the History panel.
Discovery
help(method?)
Describe every method (or one): parameters with types, ranges and defaults.
| Option | Type | Default | Description |
|---|---|---|---|
method | string | Only describe this method. |
Returns: Array of method descriptions (or one description).
await photocairn.help('crop')
info()
Describe the open image: size, layers, selection and history.
Returns: { open, name, width, height, layers: [{ index, id, name, visible, opacity, blend, isText, text?, locked }], activeLayer, selection: null | { x, y, width, height }, history: { labels, index, canUndo, canRedo } }.
await photocairn.info()
Opening and saving
open(source, { name? }?)
Open an image (JPG, PNG, WebP, AVIF, GIF, PSD), replacing the current one without asking.
| Option | Type | Default | Description |
|---|---|---|---|
source | source | required | A File or Blob, a data: URL, or an http(s) URL. URLs from other sites are blocked by the page's security policy: pass a data URL or Blob instead. |
name | string | the File's or URL's name, else "image" | File name to show and to base the export name on. |
Returns: info(). History: "Open".
await photocairn.open(dataUrl, { name: 'photo.jpg' })
newImage({ width, height, background? })
Start a new blank image, replacing the current one without asking.
| Option | Type | Default | Description |
|---|---|---|---|
width | integer, 1..8000 | required | Width in pixels. |
height | integer, 1..8000 | required | Height in pixels. |
background | color | "transparent" | "#ffffff" | Fill color, or "transparent". |
Returns: info(). History: "New image".
await photocairn.newImage({ width: 1080, height: 1080, background: 'transparent' })
getImage({ format?, quality?, maxSize? }?)
The flattened image as a data URL, optionally downscaled (cheap to show to a vision model). Never downloads.
| Option | Type | Default | Description |
|---|---|---|---|
format | "png" | "jpeg" | "webp" | "png" | Image format. |
quality | integer, 1..100 | 85 | JPEG/WebP quality. |
maxSize | integer, ≥ 0 | 0 | Longest side in pixels; larger images are scaled down. 0 = full size. |
Returns: data URL string.
await photocairn.getImage({ format: 'jpeg', maxSize: 1024 })
export({ format?, quality?, scale?, as?, download?, filename?, stripMetadata? }?)
Encode the image like File › Save. Returns it, and downloads it only if download is true.
| Option | Type | Default | Description |
|---|---|---|---|
format | "png" | "jpeg" | "webp" | "psd" | "png" | File format. psd keeps layers. |
quality | integer, 1..100 | 85 | JPEG/WebP quality. |
scale | integer, 1..100 | 100 | Size in percent of the image (not for psd). |
as | "dataURL" | "blob" | "dataURL" | Return a data URL string or a Blob. |
download | boolean | false | Also save the file through the browser's download. |
filename | string | <image name>-edited | Download file name (the extension is added). |
stripMetadata | boolean | true | Exports never contain EXIF/GPS or other metadata; false is not supported. |
Returns: data URL string, or Blob with as: 'blob'.
await photocairn.export({ format: 'webp', quality: 80 })
Geometry
crop({ x, y, width, height })
Crop the whole image (all layers) to a rectangle. The rectangle is clipped to the image.
| Option | Type | Default | Description |
|---|---|---|---|
x | number | required | Left edge of the area to keep, in image pixels. |
y | number | required | Top edge of the area to keep, in image pixels. |
width | number, ≥ 1 | required | Width of the area to keep, in pixels. |
height | number, ≥ 1 | required | Height of the area to keep, in pixels. |
Returns: info(). History: "Crop".
await photocairn.crop({ x: 100, y: 50, width: 800, height: 600 })
resize({ width?, height? }?)
Scale the whole image. Give width, height or both; with one, the aspect ratio is kept.
| Option | Type | Default | Description |
|---|---|---|---|
width | integer, 1..16000 | New width in pixels. | |
height | integer, 1..16000 | New height in pixels. |
Returns: info(). History: "Resize".
await photocairn.resize({ width: 1080 })
rotate(degrees)
Rotate the whole image clockwise. 90/180/270 are lossless; other angles grow the canvas (transparent corners).
| Option | Type | Default | Description |
|---|---|---|---|
degrees | number, -360..360 | required | Clockwise angle; negative turns counter-clockwise. |
Returns: info(). History: "Rotate 90° CW / Rotate 90° CCW / Rotate 180° / Rotate".
await photocairn.rotate(90)
flip(direction)
Mirror the whole image.
| Option | Type | Default | Description |
|---|---|---|---|
direction | "horizontal" | "vertical" | required | Which way to flip. |
Returns: info(). History: "Flip horizontal / Flip vertical".
await photocairn.flip('horizontal')
Adjustments and filters
adjust({ brightness?, contrast?, exposure?, highlights?, shadows?, saturation?, warmth?, tint?, sharpen?, soften? }?)
Light and color adjustments, sharpen and soften (Image › Adjustments). Edits the active layer, inside the selection if there is one.
| Option | Type | Default | Description |
|---|---|---|---|
brightness | integer, -100..100 | 0 | Brightness. |
contrast | integer, -100..100 | 0 | Contrast. |
exposure | integer, -100..100 | 0 | Exposure. |
highlights | integer, -100..100 | 0 | Highlights. |
shadows | integer, -100..100 | 0 | Shadows. |
saturation | integer, -100..100 | 0 | Saturation. |
warmth | integer, -100..100 | 0 | Warmth. |
tint | integer, -100..100 | 0 | Tint. |
sharpen | integer, 0..100 | 0 | Sharpen (unsharp mask). |
soften | integer, 0..100 | 0 | Soften (blur). |
Returns: info(). History: "Adjust".
await photocairn.adjust({ brightness: 15, contrast: 10, warmth: -20 })
look(name, { strength? }?)
Apply a one-tap filter (Filter › Filters) to the active layer, inside the selection if there is one.
| Option | Type | Default | Description |
|---|---|---|---|
name | "mono" | "sepia" | "invert" | "vivid" | "warm" | "cool" | "fade" | "noir" | "vintage" | required | Filter name. |
strength | integer, 0..100 | 100 | Strength in percent. |
Returns: info(). History: "Filters".
await photocairn.look('mono', { strength: 80 })
removeBackground({ model?, background?, onProgress? }?)
Cut out the main subject of the active layer with on-device AI. Downloads the model from this site on first use (then cached).
| Option | Type | Default | Description |
|---|---|---|---|
model | "fast" | "best" | "fast" | fast: 4.6 MB model. best: 44 MB model, cleaner edges. |
background | color | "transparent" | "blur" | "transparent" | New background: "transparent", a color, or "blur" for a blurred copy of the photo. |
onProgress | function | Called with { stage: 'download'|'loading'|'thinking', progress: 0..1 }. |
Returns: info(). History: "Remove background".
await photocairn.removeBackground({ model: 'fast' })
redact({ x, y, width, height, mode?, strength?, color? })
Blur, pixelate or cover a rectangle on the active layer (the Blur out tools).
| Option | Type | Default | Description |
|---|---|---|---|
x | number | required | Left edge of the area, in image pixels. |
y | number | required | Top edge of the area, in image pixels. |
width | number, ≥ 1 | required | Width of the area, in pixels. |
height | number, ≥ 1 | required | Height of the area, in pixels. |
mode | "blur" | "pixelate" | "box" | "blur" | box is a solid, irreversible cover; use it for passwords, card numbers and IDs. |
strength | integer, 10..100 | 60 | Blur/pixelate strength. |
color | color | "#000000" | Box color (mode box). |
Returns: info(). History: "Blur / Pixelate / Solid box".
await photocairn.redact({ x: 40, y: 300, width: 420, height: 60, mode: 'pixelate' })
Selection
select({ type?, x?, y?, width?, height?, points?, mode? }?)
Select a rectangle, ellipse or polygon. Later edits (adjust, look, fill, brush...) stay inside it. Not an undo step.
| Option | Type | Default | Description |
|---|---|---|---|
type | "rect" | "ellipse" | "polygon" | "rect" | Shape of the selection. |
x | number | Left edge (rect, ellipse). | |
y | number | Top edge (rect, ellipse). | |
width | number, ≥ 1 | Width (rect, ellipse). | |
height | number, ≥ 1 | Height (rect, ellipse). | |
points | points | Corners (polygon), at least 3: [{ x, y }, ...]. | |
mode | "new" | "add" | "subtract" | "intersect" | "new" | How to combine with an existing selection. |
Returns: info().selection (null if nothing ended up selected).
await photocairn.select({ type: 'ellipse', x: 200, y: 120, width: 300, height: 300 })
selectColor({ x, y, tolerance?, contiguous?, allLayers?, mode? })
Magic wand: select pixels similar in color to the one at (x, y).
| Option | Type | Default | Description |
|---|---|---|---|
x | number | required | Sample point x. |
y | number | required | Sample point y. |
tolerance | integer, 0..100 | 12 | How different a color may be and still be selected. |
contiguous | boolean | true | Only connected areas. |
allLayers | boolean | false | Sample the flattened image instead of the active layer. |
mode | "new" | "add" | "subtract" | "intersect" | "new" | How to combine with an existing selection. |
Returns: info().selection.
await photocairn.selectColor({ x: 5, y: 5, tolerance: 20 })
selectAll()
Select the whole image.
Returns: info().selection.
await photocairn.selectAll()
deselect()
Remove the selection.
Returns: null.
await photocairn.deselect()
invertSelection()
Select everything that isn't selected (selects all if nothing is).
Returns: info().selection.
await photocairn.invertSelection()
deleteSelection()
Erase the selected pixels of the active layer (to transparency).
Returns: info(). History: "Delete selection".
await photocairn.deleteSelection()
fillSelection(color)
Fill the selection (or the whole layer if nothing is selected) with a color.
| Option | Type | Default | Description |
|---|---|---|---|
color | color | required | Fill color. |
Returns: info(). History: "Fill".
await photocairn.fillSelection('#ffffff')
cropToSelection()
Crop the image to the selection's bounding box.
Returns: info(). History: "Crop to selection".
await photocairn.cropToSelection()
Drawing
fill({ x, y, color, tolerance?, contiguous?, opacity?, allLayers? })
Paint bucket: fill the area around (x, y) that has a similar color.
| Option | Type | Default | Description |
|---|---|---|---|
x | number | required | Point x. |
y | number | required | Point y. |
color | color | required | Fill color. |
tolerance | integer, 0..100 | 32 | How different a color may be and still be filled. |
contiguous | boolean | true | Only connected areas. |
opacity | integer, 1..100 | 100 | Opacity in percent. |
allLayers | boolean | false | Decide the area from the flattened image. |
Returns: info(). History: "Fill".
await photocairn.fill({ x: 10, y: 10, color: '#ff3b30' })
drawShape({ type, from, to, color?, width?, fill?, opacity? })
Draw a line, arrow, rectangle or ellipse on the active layer.
| Option | Type | Default | Description |
|---|---|---|---|
type | "line" | "arrow" | "rect" | "ellipse" | required | Shape. |
from | point | required | Start point (a corner for rect/ellipse): { x, y }. |
to | point | required | End point (the opposite corner): { x, y }. |
color | color | "#000000" | Stroke/fill color. |
width | number, 1..1000 | 4 | Line width in pixels. |
fill | boolean | false | Fill rect/ellipse instead of outlining it. |
opacity | integer, 1..100 | 100 | Opacity in percent. |
Returns: info(). History: "Line / Arrow / Rectangle / Ellipse".
await photocairn.drawShape({ type: 'arrow', from: { x: 50, y: 50 }, to: { x: 300, y: 200 }, color: '#ff3b30', width: 8 })
brushStroke({ points, kind?, size?, color?, opacity?, hardness? })
Paint one stroke through the given points with a brush, pencil, pen, highlighter or eraser.
| Option | Type | Default | Description |
|---|---|---|---|
points | points | required | Stroke path: [{ x, y }, ...] (one point makes a dot). |
kind | "brush" | "pencil" | "pen" | "highlighter" | "eraser" | "brush" | Brush type. |
size | number, 1..2000 | 12 | Tip diameter in pixels. |
color | color | "#000000" | Paint color (ignored by the eraser). |
opacity | integer, 1..100 | 100 | Opacity in percent. |
hardness | integer, 0..100 | 70 | Edge hardness (brush and eraser). |
Returns: info(). History: "Brush / Pencil / Pen / Highlighter / Eraser".
await photocairn.brushStroke({ points: [{ x: 10, y: 10 }, { x: 200, y: 80 }], size: 20, color: '#0a84ff' })
Text
addText({ text, x?, y?, size?, font?, weight?, italic?, color?, background?, outline?, align?, boxWidth? })
Add an editable text layer above the active layer.
| Option | Type | Default | Description |
|---|---|---|---|
text | string | required | The text; \n starts a new line. |
x | number | Left edge of the text box. Default: centered. | |
y | number | Top edge of the text box. Default: centered. | |
size | number, 4..2000 | 1/10 of the shorter side | Font size in pixels. |
font | string | "sans" | Font: built in "sans", "serif", "impact" (Bold), "mono", "hand" (Casual), or a library id such as "carlito" (Calibri look-alike), "tinos" (Times New Roman), "arimo" (Arial), "eb-garamond", "roboto", "lato" (see vendor/fonts/library/fonts.json). |
weight | 300 | 400 | 600 | 700 | 900 | 700 | Font weight. |
italic | boolean | false | Italic. |
color | color | "#000000" | Text color. |
background | color | "transparent" | "transparent" | Box behind the text, or "transparent". |
outline | boolean | true | Contrasting outline around the letters. |
align | "left" | "center" | "right" | "center" | Line alignment. |
boxWidth | number, ≥ 0 | 0 | Wrap lines at this width in pixels; 0 = no wrapping. |
Returns: { index, id, name, box: { x, y, width, height } }. History: "Text".
await photocairn.addText({ text: 'Hello', x: 40, y: 40, size: 64, color: '#ffffff', align: 'left' })
editText(layer, { text?, x?, y?, size?, font?, weight?, italic?, color?, background?, outline?, align?, boxWidth? }?)
Change a text layer: any addText option (text, x, y, size, color...). Unchanged options keep their values.
| Option | Type | Default | Description |
|---|---|---|---|
layer | layer | required | The text layer: index (0 = bottom) or exact name. |
text | string | New text. | |
x | number | Left edge. | |
y | number | Top edge. | |
size | number, 4..2000 | Font size. | |
font | string | Font: a built-in or library font id (see addText). | |
weight | 300 | 400 | 600 | 700 | 900 | Font weight. | |
italic | boolean | Italic. | |
color | color | Text color. | |
background | color | "transparent" | Box color or "transparent". | |
outline | boolean | Outline. | |
align | "left" | "center" | "right" | Alignment. | |
boxWidth | number, ≥ 0 | Wrap width; 0 = no wrapping. |
Returns: { index, id, name, box }. History: "Text".
await photocairn.editText(1, { text: 'Hello again', color: '#ff3b30' })
Layers
addLayer({ name?, image? }?)
Add a layer above the active one: blank, or an image scaled to fit and centered. It becomes the active layer.
| Option | Type | Default | Description |
|---|---|---|---|
name | string | Layer name. | |
image | source | Image for the layer (File/Blob/data URL/same-site URL). Default: blank. |
Returns: info(). History: "New layer / Place image".
await photocairn.addLayer({ name: 'Notes' })
selectLayer(layer)
Make a layer the active one (most edits apply to the active layer). Not an undo step.
| Option | Type | Default | Description |
|---|---|---|---|
layer | layer | required | Index (0 = bottom) or exact name. |
Returns: info().
await photocairn.selectLayer(0)
setLayer({ layer?, name?, visible?, opacity?, blend?, lock? }?)
Change a layer's name, visibility, opacity, blend mode or locks.
| Option | Type | Default | Description |
|---|---|---|---|
layer | layer | Layer to use: index (0 = bottom) or exact name. Default: the active layer. | |
name | string | New name. | |
visible | boolean | Show or hide. | |
opacity | integer, 0..100 | Opacity in percent. | |
blend | "source-over" | "multiply" | "screen" | "overlay" | "darken" | "lighten" | "color-dodge" | "color-burn" | "hard-light" | "soft-light" | "difference" | "exclusion" | "hue" | "saturation" | "color" | "luminosity" | Blend mode. | |
lock | object | Locks to set: { alpha?, pixels?, position?, all? } (booleans). |
Returns: info(). History: "Rename layer / Show layer / Hide layer / Layer opacity / Blend mode / Layer lock".
await photocairn.setLayer({ opacity: 50, blend: 'multiply' })
duplicateLayer(layer?)
Copy a layer; the copy goes above it and becomes active.
| Option | Type | Default | Description |
|---|---|---|---|
layer | layer | Layer to use: index (0 = bottom) or exact name. Default: the active layer. |
Returns: info(). History: "Duplicate layer".
await photocairn.duplicateLayer()
moveLayer(direction, { layer? }?)
Move a layer one step up or down the stack.
| Option | Type | Default | Description |
|---|---|---|---|
direction | "up" | "down" | required | Which way. |
layer | layer | Layer to use: index (0 = bottom) or exact name. Default: the active layer. |
Returns: info(). History: "Move layer up / Move layer down".
await photocairn.moveLayer('up')
deleteLayer(layer?)
Delete a layer (an image keeps at least one).
| Option | Type | Default | Description |
|---|---|---|---|
layer | layer | Layer to use: index (0 = bottom) or exact name. Default: the active layer. |
Returns: info(). History: "Delete layer".
await photocairn.deleteLayer('Notes')
mergeDown()
Merge the active layer into the one below.
Returns: info(). History: "Merge down".
await photocairn.mergeDown()
flatten()
Merge all layers into one.
Returns: info(). History: "Flatten image".
await photocairn.flatten()
History
undo(steps?)
Undo the last step(s).
| Option | Type | Default | Description |
|---|---|---|---|
steps | integer, ≥ 1 | 1 | How many steps. |
Returns: info().
await photocairn.undo()
redo(steps?)
Redo undone step(s).
| Option | Type | Default | Description |
|---|---|---|---|
steps | integer, ≥ 1 | 1 | How many steps. |
Returns: info().
await photocairn.redo()
Not in the API
These app features have no API method (yet). Most can be approximated:
- Lasso selection: use
select({ type: "polygon", points })with many points. - Move and free transform, rotating a single layer, canvas size, straighten: not available. Crop, resize, rotate and flip work on the whole image.
- Gradient, eyedropper, corners & border, merge visible: not available. To read a color, look at
getImage(). - Background touch-up brushes after
removeBackground(): erase leftovers withbrushStroke({ kind: "eraser", points, size }); restoring isn't available (undo and trymodel: "best"instead). - Clipboard copy/paste and the metadata viewer: not available. Exports never contain metadata.
open()can't fetch images from other websites (blocked by the page's security policy and cross-origin isolation): pass a data: URL or a Blob instead.