Glass lettering — Glass, Maximum and Find Edges in a text mask

Sets frosted glass letters into a photo. The text becomes a mask (made bolder with Maximum); inside it the Filter Gallery's Glass effect distorts the picture, a drop shadow adds depth and Find Edges draws the light along the rim. A Lens Flare finishes it.

INPUT
INPUT — Glass lettering — Glass, Maximum and Find Edges in a text mask
OUTPUT
OUTPUT — Glass lettering — Glass, Maximum and Find Edges in a text mask
JavaScript
// Glass lettering — PhotoCraft Glass, Maximum and Find Edges in a text mask, plus Lens Flare
// demo_photocraft_glass_text.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: TEXT:string=GLASS, TEXTURE:string=frosted
//!PARAM: DISTORTION:number=12,min=0,max=20, SMOOTHNESS:number=4,min=1,max=15
//!PARAM: BOLD:number=10,min=0,max=40, EDGE:number=0.6,min=0,max=1
//!PARAM: FLARE:boolean=true

// Frosted glass letters set into a photo. Five PhotoCraft filters and the
// engine's masking (applyMask = luminance → alpha, blend with Blend.Over) do the work:
//
//   1. mask    white text on black → filter("maximum", BOLD) fattens the strokes
//              (Other › Maximum), a light blur softens the cut
//   2. shadow  black, masked by the blurred text, laid down offset → depth
//   3. glass   copy of the photo → gallery("glass") (Filter Gallery › Distort ›
//              Glass; TEXTURE: frosted | blocks | canvas | tinyLens) → masked:
//              the distortion shows only inside the letters
//   4. edge    filter("findEdges") + filter("invert") on the mask → a thin white
//              rim, the light catching the glass edge (EDGE = its opacity)
//   5. filter("lensFlare") — optional highlight, positioned in normalized coords

const img = Engine.loadImage(INPUT);
const scale = Math.min(1, 1024 / Math.max(img.width, img.height));
if (scale < 1) img.resize(Math.round(img.width * scale), Math.round(img.height * scale));
const W = img.width, H = img.height;

// ── 1. Text mask ───────────────────────────────────────────────────────────
const mask = Engine.createImage(W, H, new Pixel(0, 0, 0, 1));
const size = Math.round(Math.min(H * 0.45, (W * 0.85) / Math.max(1, TEXT.length) * 1.6));
mask.drawText(TEXT, W / 2, H / 2 + size * 0.36, {
  font: "Inter", size, anchor: "middle", color: new Pixel(1, 1, 1, 1),
});
if (BOLD > 0) mask.filter("maximum", { radius: BOLD, preserve: "roundness" });
mask.gaussianBlur(1.5);

// ── 2. Drop shadow ─────────────────────────────────────────────────────────
const off = Math.max(2, Math.round(size / 40));
const shadow = Engine.createImage(W, H, new Pixel(0, 0, 0, 1))
  .applyMask(mask.clone().gaussianBlur(off * 2));
img.blendAt(shadow, px(off, off), 0.45, Blend.Over);

// ── 3. Glass inside the letters ────────────────────────────────────────────
const glass = img.clone()
  .gallery("glass", { distortion: DISTORTION, smoothness: SMOOTHNESS, texture: TEXTURE, scaling: 120 })
  .brightness(1.08)
  .applyMask(mask);
img.blend(glass, 1.0, Blend.Over);

// ── 4. Light on the edge ───────────────────────────────────────────────────
if (EDGE > 0) {
  const rim = Engine.createImage(W, H, new Pixel(1, 1, 1, 1))
    .applyMask(mask.clone().filter("findEdges").filter("invert").gaussianBlur(1));
  img.blend(rim, EDGE, Blend.Over);
  rim.free();
}

if (FLARE) img.filter("lensFlare", { brightness: 110, centerX: 0.78, centerY: 0.22, lens: "prime105" });

img.save(OUTPUT);
mask.free();
shadow.free();
glass.free();