Apply Adjustment
photopea_apply_adjustmentApply destructive adjustments like brightness, hue/saturation, levels, or curves to the active layer. Modify pixel data directly; use undo to revert. Requires prior layer selection.
Instructions
Apply a destructive image adjustment to the active layer's pixel data. Use select_layer to target a specific layer first. Modifies pixels directly — use undo to revert if needed.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | Adjustment type: 'brightness' for brightness/contrast, 'hue_sat' for hue/saturation/lightness, 'levels' for input levels, 'curves' for tone curves | |
| settings | No | Key-value settings for the adjustment. For brightness: { brightness: -100..100, contrast: -100..100 }. For hue_sat: { hue: -180..180, saturation: -100..100, lightness: -100..100 }. For levels: { inputBlack: 0..255, inputWhite: 0..255 } |
Implementation Reference
- src/bridge/script-builder.ts:551-594 (handler)The core handler function that builds the Photopea JavaScript script for applying adjustments. Supports brightness/contrast, hue/saturation/lightness, levels, and curves adjustments based on params type and settings.
export function buildApplyAdjustment(params: ApplyAdjustmentParams): string { const { type, settings = {} } = params; const lines: string[] = []; const layer = `app.activeDocument.activeLayer`; switch (type) { case "brightness": { const brightness = (settings.brightness as number) ?? 0; const contrast = (settings.contrast as number) ?? 0; lines.push(`${layer}.adjustBrightnessContrast(${brightness}, ${contrast});`); break; } case "hue_sat": { const hue = (settings.hue as number) ?? 0; const saturation = (settings.saturation as number) ?? 0; const lightness = (settings.lightness as number) ?? 0; lines.push(`${layer}.adjustColorBalance(${hue}, ${saturation}, ${lightness});`); break; } case "levels": { const inputMin = (settings.inputMin as number) ?? 0; const inputMax = (settings.inputMax as number) ?? 255; const gamma = (settings.gamma as number) ?? 1; const outputMin = (settings.outputMin as number) ?? 0; const outputMax = (settings.outputMax as number) ?? 255; lines.push( `${layer}.adjustLevels(${inputMin}, ${inputMax}, ${gamma}, ${outputMin}, ${outputMax});` ); break; } case "curves": { const curvePoints = typeof settings.points === "string" && /^[\[\]0-9,.\s-]+$/.test(settings.points) ? settings.points : "[[0,0],[255,255]]"; lines.push(`${layer}.adjustCurves(${curvePoints});`); break; } default: lines.push(`// Unknown adjustment type: ${type}`); } lines.push(`app.echoToOE('ok');`); return lines.join("\n"); } - src/tools/image.ts:96-111 (registration)Registration of the 'photopea_apply_adjustment' MCP tool with its input schema (type enum + optional settings record), annotations, and the async handler that calls buildApplyAdjustment and executes via bridge.
// 20. photopea_apply_adjustment server.registerTool("photopea_apply_adjustment", { title: "Apply Adjustment", description: "Apply a destructive image adjustment to the active layer's pixel data. Use select_layer to target a specific layer first. Modifies pixels directly — use undo to revert if needed.", inputSchema: { type: z.enum(["brightness", "hue_sat", "levels", "curves"]).describe("Adjustment type: 'brightness' for brightness/contrast, 'hue_sat' for hue/saturation/lightness, 'levels' for input levels, 'curves' for tone curves"), settings: z.record(z.union([z.number(), z.string(), z.boolean()])).optional().describe("Key-value settings for the adjustment. For brightness: { brightness: -100..100, contrast: -100..100 }. For hue_sat: { hue: -180..180, saturation: -100..100, lightness: -100..100 }. For levels: { inputBlack: 0..255, inputWhite: 0..255 }"), }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }, }, async (params) => { const script = buildApplyAdjustment(params); bridge.sendActivity({ type: "activity", id: "", tool: "apply_adjustment", summary: `Apply ${params.type} adjustment` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to apply adjustment" }] }; return { content: [{ type: "text" as const, text: `Adjustment applied: ${params.type}` }] }; }); - src/bridge/types.ts:195-198 (schema)TypeScript interface defining the ApplyAdjustmentParams: type (string) and optional settings record for adjustment parameters.
export interface ApplyAdjustmentParams { type: string; settings?: Record<string, number | string | boolean>; }