Filter-Browser — jeder Filter mit seinen Einstellungen
Einer von rund 155 Filtern aus einer durchsuchbaren Liste — Photoshops Filter-Menü und Filtergalerie (PhotoCraft), die eigenen Filter der Engine und Erweiterungen. Darunter erscheinen seine Einstellungen, eine Live-Vorschau folgt jeder Änderung. Links das Original, rechts gefiltert.
INPUT
OUTPUT
JavaScript
// Every filter in one picker — PhotoCraft, the engine's own and extensions, with live preview
// demo_photocraft.js
//!TITLE: Filter browser — every filter with its settings
//!DESC: Pick any of ~155 filters (Photoshop's Filter menu and Filter Gallery via PhotoCraft,
//!DESC: the engine's own filters, extensions). Its settings appear below the picker; the
//!DESC: preview follows every change. Left half original, right half filtered.
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: FX:filter=oilPaint
//!LIVE: true,preview=256
//!SAMPLE watercolor(FX=pc.filter.gallery.watercolor)
//!SAMPLE brushed(FX=os.anisotropicKuwahara)
//!SAMPLE tiltShift(FX=pc.filter.blurGallery.tiltShift)
// FX is the picker's value — `{ "filter": "<id>", …changed settings }` —
// and img.filter() takes it as it is. On the command line:
// mlcos-run demo_photocraft.js --INPUT=in.jpg --OUTPUT=out.webp --FX=os.kuwahara
// … --FX='{"filter":"pc.filter.distort.twirl","angle":200}'
//
// The image keeps its size on purpose: filters measure in pixels, and
// the live preview scales those values to its smaller input. A script
// that resized the input itself would make the preview misleading.
const src = Engine.loadImage(INPUT);
const out = src.clone().filter(FX);
// Before/after: left half of the original over the filtered image,
// a thin line in between.
const half = Math.floor(src.width / 2);
const left = src.clone().crop(0, 0, half, src.height);
out.blendAt(left, px(0, 0), 1.0, Blend.Over);
const line = Math.max(1, Math.round(2 * src.width / 1280));
out.fillRectangle(half - Math.floor(line / 2), 0, line, src.height, "#ffffff");
// Which filter ran — FX is a name, an id, JSON text or (CLI) an object.
let chosen = FX;
if (typeof chosen === "string" && chosen.trim().startsWith("{")) chosen = JSON.parse(chosen);
const name = typeof chosen === "object" ? chosen.filter : String(chosen).split(",")[0];
const info = Engine.filters().find(f => f.id === name || f.name === name);
if (info) console.log(`${info.labels.en} — ${info.id}`);
out.save(OUTPUT);
left.free();
src.free();