Photocairn for developers & AI agents Open the editor

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

Quick start for agents

  1. Open https://photocairn.silicairn.com/ in the browser.
  2. window.photocairn is ready once the page has loaded (it also fires a photocairn:ready event on window).
  3. 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

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

Selecting and moving

Image

Painting

Photo

Layers and history

Keyboard shortcuts

ActionKeys
Move / Select / CropV / M / C
Next selection tool (Ellipse, Lasso, Polygon, Magic wand)M again / Shift+M
Magic wandW
Brush tools / Pencil / EraserB / N / E
Next brush tool (Pencil, Pen, Highlighter)B again / Shift+B
Fill tools / Paint bucketG / K
Next fill tool (Paint bucket, Gradient)G again / Shift+G
EyedropperI
Shapes / TextU / T
Next shape (Line, Arrow, Rectangle, Ellipse)U again / Shift+U
Free transformCtrl+Alt+T
Snap on / offCtrl+Shift+;
Swap / reset colorsX / D
Brush or text size[ / ]
Select all / Deselect / Invert selectionCtrl+A / Ctrl+D / Ctrl+Shift+I
Copy / Cut / PasteCtrl+C / Ctrl+X / Ctrl+V
Selection to new layerCtrl+J
New layer / Merge downCtrl+Shift+N / Ctrl+E
Delete selected pixelsDelete
Undo / RedoCtrl+Z / Ctrl+Shift+Z or Ctrl+Y
Open / SaveCtrl+O / Ctrl+S
Zoom in / out, Fit, 100%+ / −, 0, 1
Panhold Space
Compare with the originalhold \
Layers panelL
Apply (crop, transform) / Cancel or deselectEnter / 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.

OptionTypeDefaultDescription
methodstringOnly 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.

OptionTypeDefaultDescription
sourcesourcerequiredA 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.
namestringthe 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.

OptionTypeDefaultDescription
widthinteger, 1..8000requiredWidth in pixels.
heightinteger, 1..8000requiredHeight in pixels.
backgroundcolor | "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.

OptionTypeDefaultDescription
format"png" | "jpeg" | "webp""png"Image format.
qualityinteger, 1..10085JPEG/WebP quality.
maxSizeinteger, ≥ 00Longest 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.

OptionTypeDefaultDescription
format"png" | "jpeg" | "webp" | "psd""png"File format. psd keeps layers.
qualityinteger, 1..10085JPEG/WebP quality.
scaleinteger, 1..100100Size in percent of the image (not for psd).
as"dataURL" | "blob""dataURL"Return a data URL string or a Blob.
downloadbooleanfalseAlso save the file through the browser's download.
filenamestring<image name>-editedDownload file name (the extension is added).
stripMetadatabooleantrueExports 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.

OptionTypeDefaultDescription
xnumberrequiredLeft edge of the area to keep, in image pixels.
ynumberrequiredTop edge of the area to keep, in image pixels.
widthnumber, ≥ 1requiredWidth of the area to keep, in pixels.
heightnumber, ≥ 1requiredHeight 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.

OptionTypeDefaultDescription
widthinteger, 1..16000New width in pixels.
heightinteger, 1..16000New 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).

OptionTypeDefaultDescription
degreesnumber, -360..360requiredClockwise 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.

OptionTypeDefaultDescription
direction"horizontal" | "vertical"requiredWhich 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.

OptionTypeDefaultDescription
brightnessinteger, -100..1000Brightness.
contrastinteger, -100..1000Contrast.
exposureinteger, -100..1000Exposure.
highlightsinteger, -100..1000Highlights.
shadowsinteger, -100..1000Shadows.
saturationinteger, -100..1000Saturation.
warmthinteger, -100..1000Warmth.
tintinteger, -100..1000Tint.
sharpeninteger, 0..1000Sharpen (unsharp mask).
softeninteger, 0..1000Soften (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.

OptionTypeDefaultDescription
name"mono" | "sepia" | "invert" | "vivid" | "warm" | "cool" | "fade" | "noir" | "vintage"requiredFilter name.
strengthinteger, 0..100100Strength 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).

OptionTypeDefaultDescription
model"fast" | "best""fast"fast: 4.6 MB model. best: 44 MB model, cleaner edges.
backgroundcolor | "transparent" | "blur""transparent"New background: "transparent", a color, or "blur" for a blurred copy of the photo.
onProgressfunctionCalled 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).

OptionTypeDefaultDescription
xnumberrequiredLeft edge of the area, in image pixels.
ynumberrequiredTop edge of the area, in image pixels.
widthnumber, ≥ 1requiredWidth of the area, in pixels.
heightnumber, ≥ 1requiredHeight of the area, in pixels.
mode"blur" | "pixelate" | "box""blur"box is a solid, irreversible cover; use it for passwords, card numbers and IDs.
strengthinteger, 10..10060Blur/pixelate strength.
colorcolor"#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.

OptionTypeDefaultDescription
type"rect" | "ellipse" | "polygon""rect"Shape of the selection.
xnumberLeft edge (rect, ellipse).
ynumberTop edge (rect, ellipse).
widthnumber, ≥ 1Width (rect, ellipse).
heightnumber, ≥ 1Height (rect, ellipse).
pointspointsCorners (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).

OptionTypeDefaultDescription
xnumberrequiredSample point x.
ynumberrequiredSample point y.
toleranceinteger, 0..10012How different a color may be and still be selected.
contiguousbooleantrueOnly connected areas.
allLayersbooleanfalseSample 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.

OptionTypeDefaultDescription
colorcolorrequiredFill 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.

OptionTypeDefaultDescription
xnumberrequiredPoint x.
ynumberrequiredPoint y.
colorcolorrequiredFill color.
toleranceinteger, 0..10032How different a color may be and still be filled.
contiguousbooleantrueOnly connected areas.
opacityinteger, 1..100100Opacity in percent.
allLayersbooleanfalseDecide 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.

OptionTypeDefaultDescription
type"line" | "arrow" | "rect" | "ellipse"requiredShape.
frompointrequiredStart point (a corner for rect/ellipse): { x, y }.
topointrequiredEnd point (the opposite corner): { x, y }.
colorcolor"#000000"Stroke/fill color.
widthnumber, 1..10004Line width in pixels.
fillbooleanfalseFill rect/ellipse instead of outlining it.
opacityinteger, 1..100100Opacity 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.

OptionTypeDefaultDescription
pointspointsrequiredStroke path: [{ x, y }, ...] (one point makes a dot).
kind"brush" | "pencil" | "pen" | "highlighter" | "eraser""brush"Brush type.
sizenumber, 1..200012Tip diameter in pixels.
colorcolor"#000000"Paint color (ignored by the eraser).
opacityinteger, 1..100100Opacity in percent.
hardnessinteger, 0..10070Edge 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.

OptionTypeDefaultDescription
textstringrequiredThe text; \n starts a new line.
xnumberLeft edge of the text box. Default: centered.
ynumberTop edge of the text box. Default: centered.
sizenumber, 4..20001/10 of the shorter sideFont size in pixels.
fontstring"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).
weight300 | 400 | 600 | 700 | 900700Font weight.
italicbooleanfalseItalic.
colorcolor"#000000"Text color.
backgroundcolor | "transparent""transparent"Box behind the text, or "transparent".
outlinebooleantrueContrasting outline around the letters.
align"left" | "center" | "right""center"Line alignment.
boxWidthnumber, ≥ 00Wrap 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.

OptionTypeDefaultDescription
layerlayerrequiredThe text layer: index (0 = bottom) or exact name.
textstringNew text.
xnumberLeft edge.
ynumberTop edge.
sizenumber, 4..2000Font size.
fontstringFont: a built-in or library font id (see addText).
weight300 | 400 | 600 | 700 | 900Font weight.
italicbooleanItalic.
colorcolorText color.
backgroundcolor | "transparent"Box color or "transparent".
outlinebooleanOutline.
align"left" | "center" | "right"Alignment.
boxWidthnumber, ≥ 0Wrap 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.

OptionTypeDefaultDescription
namestringLayer name.
imagesourceImage 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.

OptionTypeDefaultDescription
layerlayerrequiredIndex (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.

OptionTypeDefaultDescription
layerlayerLayer to use: index (0 = bottom) or exact name. Default: the active layer.
namestringNew name.
visiblebooleanShow or hide.
opacityinteger, 0..100Opacity 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.
lockobjectLocks 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.

OptionTypeDefaultDescription
layerlayerLayer 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.

OptionTypeDefaultDescription
direction"up" | "down"requiredWhich way.
layerlayerLayer 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).

OptionTypeDefaultDescription
layerlayerLayer 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).

OptionTypeDefaultDescription
stepsinteger, ≥ 11How many steps.

Returns: info().

await photocairn.undo()

redo(steps?)

Redo undone step(s).

OptionTypeDefaultDescription
stepsinteger, ≥ 11How many steps.

Returns: info().

await photocairn.redo()

Not in the API

These app features have no API method (yet). Most can be approximated: