Modify Selection
photopea_modify_selectionModify an existing selection by expanding, contracting, feathering edges, or inverting selected and unselected areas. Specify amount in pixels for expand, contract, or feather.
Instructions
Modify the current active selection. Requires an existing selection created by make_selection. For expand, contract, and feather, the amount parameter specifies pixels. Invert swaps selected and unselected areas.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | How to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected | |
| amount | No | Modification amount in pixels (required for expand, contract, feather; ignored for invert) |
Implementation Reference
- src/tools/image.ts:197-211 (registration)Registration of the 'photopea_modify_selection' tool with input schema (action enum + optional amount) and handler that delegates to buildModifySelection.
server.registerTool("photopea_modify_selection", { title: "Modify Selection", description: "Modify the current active selection. Requires an existing selection created by make_selection. For expand, contract, and feather, the amount parameter specifies pixels. Invert swaps selected and unselected areas.", inputSchema: { action: z.enum(["expand", "contract", "feather", "invert"]).describe("How to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected"), amount: z.number().min(0).optional().describe("Modification amount in pixels (required for expand, contract, feather; ignored for invert)"), }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }, }, async (params) => { const script = buildModifySelection(params); bridge.sendActivity({ type: "activity", id: "", tool: "modify_selection", summary: `Modify selection: ${params.action}` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to modify selection" }] }; return { content: [{ type: "text" as const, text: `Selection modified: ${params.action}` }] }; }); - src/tools/image.ts:205-211 (handler)Handler function for photopea_modify_selection: builds script, sends activity, executes script, returns result or error.
}, async (params) => { const script = buildModifySelection(params); bridge.sendActivity({ type: "activity", id: "", tool: "modify_selection", summary: `Modify selection: ${params.action}` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to modify selection" }] }; return { content: [{ type: "text" as const, text: `Selection modified: ${params.action}` }] }; }); - src/tools/image.ts:200-203 (schema)Input schema for photopea_modify_selection: 'action' (enum: expand/contract/feather/invert) and optional 'amount' (number, min 0).
inputSchema: { action: z.enum(["expand", "contract", "feather", "invert"]).describe("How to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected"), amount: z.number().min(0).optional().describe("Modification amount in pixels (required for expand, contract, feather; ignored for invert)"), }, - src/bridge/script-builder.ts:753-775 (helper)buildModifySelection function: generates Photopea JavaScript string for selection modification (expand, contract, feather, or invert).
export function buildModifySelection(params: ModifySelectionParams): string { const { action, amount = 0 } = params; const lines: string[] = []; const sel = `app.activeDocument.selection`; switch (action) { case "expand": lines.push(`${sel}.expand(${amount});`); break; case "contract": lines.push(`${sel}.contract(${amount});`); break; case "feather": lines.push(`${sel}.feather(${amount});`); break; case "invert": lines.push(`${sel}.invert();`); break; } lines.push(`app.echoToOE('ok');`); return lines.join("\n"); } - src/bridge/types.ts:227-230 (helper)Type definition for ModifySelectionParams: action (expand/contract/feather/invert) and optional amount.
export interface ModifySelectionParams { action: "expand" | "contract" | "feather" | "invert"; amount?: number; }