Add Fill Layer
photopea_add_fill_layerAdd a non-destructive solid color fill layer covering the entire canvas. This adjustment-style layer can be toggled, recolored, or deleted without affecting other layers. Adjust its opacity or blend mode using set_layer_properties.
Instructions
Add a non-destructive solid color fill layer that covers the entire canvas. Unlike fill_selection, this creates a separate adjustment-style layer that can be toggled, recolored, or deleted without affecting other layers. Use set_layer_properties to change its opacity or blend mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | Fill layer type (currently only 'solid' is supported) | |
| color | Yes | Fill color as hex string (e.g. #ff0000) | |
| name | No | Display name for the fill layer in the layers panel |
Implementation Reference
- src/tools/layer.ts:42-57 (registration)Registration of the photopea_add_fill_layer tool on the MCP server, including inputSchema definition and handler that calls buildAddFillLayer.
server.registerTool("photopea_add_fill_layer", { title: "Add Fill Layer", description: "Add a non-destructive solid color fill layer that covers the entire canvas. Unlike fill_selection, this creates a separate adjustment-style layer that can be toggled, recolored, or deleted without affecting other layers. Use set_layer_properties to change its opacity or blend mode.", inputSchema: { type: z.enum(["solid"]).describe("Fill layer type (currently only 'solid' is supported)"), color: z.string().regex(/^#[0-9a-fA-F]{6}$/).describe("Fill color as hex string (e.g. #ff0000)"), name: z.string().optional().describe("Display name for the fill layer in the layers panel"), }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }, }, async (params) => { const script = buildAddFillLayer(params); bridge.sendActivity({ type: "activity", id: "", tool: "add_fill_layer", summary: `Add ${params.type} fill layer` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to add fill layer" }] }; return { content: [{ type: "text" as const, text: `Fill layer (${params.type}) added` }] }; }); - src/tools/layer.ts:45-49 (schema)Input schema for photopea_add_fill_layer: type (enum 'solid'), color (hex regex), and optional name.
inputSchema: { type: z.enum(["solid"]).describe("Fill layer type (currently only 'solid' is supported)"), color: z.string().regex(/^#[0-9a-fA-F]{6}$/).describe("Fill color as hex string (e.g. #ff0000)"), name: z.string().optional().describe("Display name for the fill layer in the layers panel"), }, - src/tools/layer.ts:51-57 (handler)Handler function for photopea_add_fill_layer: builds script from params, sends activity, executes via bridge, returns success/error response.
}, async (params) => { const script = buildAddFillLayer(params); bridge.sendActivity({ type: "activity", id: "", tool: "add_fill_layer", summary: `Add ${params.type} fill layer` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to add fill layer" }] }; return { content: [{ type: "text" as const, text: `Fill layer (${params.type}) added` }] }; }); - src/bridge/script-builder.ts:227-250 (helper)buildAddFillLayer helper function that constructs the Photopea JavaScript to create a new art layer and fill the selection with a solid color.
export function buildAddFillLayer(params: AddFillLayerParams): string { const { type, color, name } = params; const lines: string[] = []; if (type === "solid" && color) { const { r, g, b } = hexToRgb(color); lines.push(solidColorLines("_fillColor", r, g, b)); lines.push(`var _layer = app.activeDocument.artLayers.add();`); if (name !== undefined) { lines.push(`_layer.name = '${escapeString(name)}';`); } lines.push(`app.activeDocument.selection.selectAll();`); lines.push(`app.activeDocument.selection.fill(_fillColor);`); lines.push(`app.activeDocument.selection.deselect();`); } else { lines.push(`var _layer = app.activeDocument.artLayers.add();`); if (name !== undefined) { lines.push(`_layer.name = '${escapeString(name)}';`); } } lines.push(`app.echoToOE('ok');`); return lines.join("\n"); } - src/bridge/types.ts:110-114 (helper)AddFillLayerParams type definition used by both schema and buildAddFillLayer.
export interface AddFillLayerParams { type: "solid"; color?: string; name?: string; }