diff --git a/public/site/results/carousel-1.avif b/public/site/results/carousel-1.avif new file mode 100644 index 0000000..9ec6690 Binary files /dev/null and b/public/site/results/carousel-1.avif differ diff --git a/public/site/results/carousel-1.webp b/public/site/results/carousel-1.webp new file mode 100644 index 0000000..b83ef25 Binary files /dev/null and b/public/site/results/carousel-1.webp differ diff --git a/public/site/results/carousel-2.avif b/public/site/results/carousel-2.avif new file mode 100644 index 0000000..9fcfe10 Binary files /dev/null and b/public/site/results/carousel-2.avif differ diff --git a/public/site/results/carousel-2.webp b/public/site/results/carousel-2.webp new file mode 100644 index 0000000..669e0ad Binary files /dev/null and b/public/site/results/carousel-2.webp differ diff --git a/public/site/results/carousel-3.avif b/public/site/results/carousel-3.avif new file mode 100644 index 0000000..446b513 Binary files /dev/null and b/public/site/results/carousel-3.avif differ diff --git a/public/site/results/carousel-3.webp b/public/site/results/carousel-3.webp new file mode 100644 index 0000000..dab79e7 Binary files /dev/null and b/public/site/results/carousel-3.webp differ diff --git a/public/site/results/carousel-source.avif b/public/site/results/carousel-source.avif new file mode 100644 index 0000000..929c438 Binary files /dev/null and b/public/site/results/carousel-source.avif differ diff --git a/public/site/results/carousel-source.webp b/public/site/results/carousel-source.webp new file mode 100644 index 0000000..3e8ce0e Binary files /dev/null and b/public/site/results/carousel-source.webp differ diff --git a/public/site/results/cutout-after.avif b/public/site/results/cutout-after.avif new file mode 100644 index 0000000..cf8724d Binary files /dev/null and b/public/site/results/cutout-after.avif differ diff --git a/public/site/results/cutout-after.webp b/public/site/results/cutout-after.webp new file mode 100644 index 0000000..ed6bca6 Binary files /dev/null and b/public/site/results/cutout-after.webp differ diff --git a/public/site/results/cutout-before.avif b/public/site/results/cutout-before.avif new file mode 100644 index 0000000..d15e5de Binary files /dev/null and b/public/site/results/cutout-before.avif differ diff --git a/public/site/results/cutout-before.webp b/public/site/results/cutout-before.webp new file mode 100644 index 0000000..5a1fb0a Binary files /dev/null and b/public/site/results/cutout-before.webp differ diff --git a/public/site/results/develop-after.avif b/public/site/results/develop-after.avif new file mode 100644 index 0000000..e15595d Binary files /dev/null and b/public/site/results/develop-after.avif differ diff --git a/public/site/results/develop-after.webp b/public/site/results/develop-after.webp new file mode 100644 index 0000000..148fdf9 Binary files /dev/null and b/public/site/results/develop-after.webp differ diff --git a/public/site/results/develop-before.avif b/public/site/results/develop-before.avif new file mode 100644 index 0000000..8254887 Binary files /dev/null and b/public/site/results/develop-before.avif differ diff --git a/public/site/results/develop-before.webp b/public/site/results/develop-before.webp new file mode 100644 index 0000000..ad721a4 Binary files /dev/null and b/public/site/results/develop-before.webp differ diff --git a/public/site/results/remove-after.avif b/public/site/results/remove-after.avif new file mode 100644 index 0000000..b53b9b0 Binary files /dev/null and b/public/site/results/remove-after.avif differ diff --git a/public/site/results/remove-after.webp b/public/site/results/remove-after.webp new file mode 100644 index 0000000..3d29d02 Binary files /dev/null and b/public/site/results/remove-after.webp differ diff --git a/public/site/results/remove-before.avif b/public/site/results/remove-before.avif new file mode 100644 index 0000000..90f76e1 Binary files /dev/null and b/public/site/results/remove-before.avif differ diff --git a/public/site/results/remove-before.webp b/public/site/results/remove-before.webp new file mode 100644 index 0000000..9ac4d50 Binary files /dev/null and b/public/site/results/remove-before.webp differ diff --git a/public/site/results/upscale-after.avif b/public/site/results/upscale-after.avif new file mode 100644 index 0000000..8378128 Binary files /dev/null and b/public/site/results/upscale-after.avif differ diff --git a/public/site/results/upscale-after.webp b/public/site/results/upscale-after.webp new file mode 100644 index 0000000..d85bfd3 Binary files /dev/null and b/public/site/results/upscale-after.webp differ diff --git a/public/site/results/upscale-before.avif b/public/site/results/upscale-before.avif new file mode 100644 index 0000000..59c45ec Binary files /dev/null and b/public/site/results/upscale-before.avif differ diff --git a/public/site/results/upscale-before.webp b/public/site/results/upscale-before.webp new file mode 100644 index 0000000..c6a1598 Binary files /dev/null and b/public/site/results/upscale-before.webp differ diff --git a/scripts/build-result-stills.mjs b/scripts/build-result-stills.mjs new file mode 100644 index 0000000..804b100 --- /dev/null +++ b/scripts/build-result-stills.mjs @@ -0,0 +1,417 @@ +/** + * Honest marketing stills for the home page and the tool pages. + * + * Every pixel comes from a file in public/samples/ and from code that already + * ships with the editor. Nothing is painted by hand. + * + * develop-*.{webp,avif} + * public/samples/twelve-apostles.jpg, plain, and the same pixels after + * processImageSync (src/lib/imageProcessing.ts) with the slider values + * promo/scripts/capture-hero.mjs uses for this photo: + * exposure 0.85, contrast 26, highlights -65, shadows 85, whites 25, + * blacks -20, temperature 22, vibrance 55, saturation 8, clarity 32, + * dehaze 30. + * The file is the flat JPEG the editor ships. The camera RAW it was + * developed from is not in the repo, so this is not a sensor decode. + * + * cutout-*.{webp,avif} + * public/samples/pagoda.jpg. The subject mask is IS-Net general use, + * public/models/isnet-general-use-int8.onnx, run the way ai.worker.ts + * runs it (1024², RGB/peak − 0.5, min–max to 0–1). Specks are dropped + * with cleanCutout from src/lib/cutout.ts. The after image keeps the + * photo's colour and uses the mask as alpha (transparent background). + * The square input is drawImage()'d with @napi-rs/canvas, same call the + * browser uses, not a hand-drawn matte. + * + * remove-*.{webp,avif} + * A crop of pagoda.jpg. The person standing on open gravel is one Heal spot + * (src/lib/heal.ts): it copies gravel from up and to the left and blends it + * into the surroundings. The centre was read off a 2× crop of this file. + * The second person stands against the eaves; a gravel source leaves a dark + * patch there, so the still does not claim to remove them. MI-GAN on these + * figures filled the hole with foliage, so the still uses Heal. + * + * upscale-*.{webp,avif} + * A roof crop of pagoda.jpg scaled down so the long edge is 256 px. + * Before: that small crop enlarged 2× with lanczos (a smooth resize). + * After: Real-ESRGAN general x4v3 (public/models/realesr-general-x4v3.onnx) + * tiled the way src/lib/upscale.worker.ts tiles, asked for 2×, then mixed + * with 20% of the smooth resize — TEXTURE_MIX in src/lib/upscale.ts. + * + * carousel-source and carousel-1..3 + * twelve-apostles.jpg in the Panorama layout: one frame across 3 slides, + * aspect 4:5, cover-fit, painted by paintCarouselSlide (src/lib/carouselPaint.js). + * Slides are 540×675, half of the 1080×1350 export, so the crop matches export. + * + * Run from the repo root: + * node --experimental-strip-types --import ./scripts/register-ts.mjs scripts/build-result-stills.mjs + * Pass --only develop|cutout|remove|upscale|carousel to regenerate one set. + */ +import { mkdir, readFile } from 'node:fs/promises' +import { createCanvas, loadImage } from '@napi-rs/canvas' +import * as ort from 'onnxruntime-web' +import sharp from 'sharp' +import { cleanCutout } from '../src/lib/cutout.ts' +import { applyHeal } from '../src/lib/heal.ts' +import { paintCarouselSlide } from '../src/lib/carouselPaint.js' +import { processImageSync } from '../src/lib/imageProcessing.ts' +import { cloneEdits, DEFAULT_EDITS } from '../src/types/edits.ts' + +const OUT = new URL('../public/site/results/', import.meta.url) +const PAGODA = new URL('../public/samples/pagoda.jpg', import.meta.url) +const APOSTLES = new URL('../public/samples/twelve-apostles.jpg', import.meta.url) +const SEGMENT = new URL('../public/models/isnet-general-use-int8.onnx', import.meta.url) +const UPSCALE = new URL('../public/models/realesr-general-x4v3.onnx', import.meta.url) +ort.env.wasm.numThreads = 1 +ort.env.wasm.wasmPaths = new URL('../node_modules/onnxruntime-web/dist/', import.meta.url).href + +const manifest = {} + +async function session(url) { + const bytes = await readFile(url) + return ort.InferenceSession.create(bytes, { executionProviders: ['wasm'] }) +} + +async function writeStill(name, rgba, width, height) { + const input = Buffer.from(rgba.buffer, rgba.byteOffset, rgba.byteLength) + const base = new URL(name, OUT) + await sharp(input, { raw: { width, height, channels: 4 } }) + .webp({ quality: 78, alphaQuality: 90, effort: 4 }) + .toFile(`${base.pathname}.webp`) + await sharp(input, { raw: { width, height, channels: 4 } }) + .avif({ quality: 50, effort: 4 }) + .toFile(`${base.pathname}.avif`) + manifest[name] = { width, height } + console.log('wrote', name, width, height) +} + +async function resizeRgba(rgba, width, height, toW, toH) { + const out = await sharp(Buffer.from(rgba.buffer, rgba.byteOffset, rgba.byteLength), { + raw: { width, height, channels: 4 }, + }) + .resize(toW, toH, { fit: 'fill' }) + .ensureAlpha() + .raw() + .toBuffer() + return new Uint8ClampedArray(out.buffer, out.byteOffset, out.byteLength) +} + +async function develop() { + const image = await loadImage(APOSTLES) + const canvas = createCanvas(image.width, image.height) + const ctx = canvas.getContext('2d') + ctx.drawImage(image, 0, 0) + const before = ctx.getImageData(0, 0, image.width, image.height) + const edits = cloneEdits(DEFAULT_EDITS) + Object.assign(edits, { + exposure: 0.85, + contrast: 26, + highlights: -65, + shadows: 85, + whites: 25, + blacks: -20, + temperature: 22, + vibrance: 55, + saturation: 8, + clarity: 32, + dehaze: 30, + }) + const after = new (before.constructor)(new Uint8ClampedArray(before.data), before.width, before.height) + after.data.set(before.data) + processImageSync(after, edits) + const w = 1200 + const h = Math.round((image.height * w) / image.width) + await writeStill('develop-before', await resizeRgba(before.data, before.width, before.height, w, h), w, h) + await writeStill('develop-after', await resizeRgba(after.data, after.width, after.height, w, h), w, h) +} + +function sampleMask(mask, n, x, y, imgW, imgH) { + const fx = Math.min(n - 1, Math.max(0, ((x + 0.5) * n) / imgW - 0.5)) + const fy = Math.min(n - 1, Math.max(0, ((y + 0.5) * n) / imgH - 0.5)) + const x0 = Math.floor(fx) + const y0 = Math.floor(fy) + const x1 = Math.min(n - 1, x0 + 1) + const y1 = Math.min(n - 1, y0 + 1) + const tx = fx - x0 + const ty = fy - y0 + const at = (px, py) => mask[py * n + px] + const top = at(x0, y0) + (at(x1, y0) - at(x0, y0)) * tx + const bottom = at(x0, y1) + (at(x1, y1) - at(x0, y1)) * tx + return top + (bottom - top) * ty +} + +async function cutout() { + console.log('segment…') + const image = await loadImage(PAGODA) + const s = await session(SEGMENT) + const square = createCanvas(1024, 1024) + const sq = square.getContext('2d') + sq.drawImage(image, 0, 0, 1024, 1024) + const rgba = sq.getImageData(0, 0, 1024, 1024).data + const plane = 1024 * 1024 + let peak = 1 + for (let i = 0; i < rgba.length; i += 4) peak = Math.max(peak, rgba[i], rgba[i + 1], rgba[i + 2]) + const input = new Float32Array(plane * 3) + for (let k = 0, i = 0; k < plane; k++, i += 4) { + input[k] = rgba[i] / peak - 0.5 + input[plane + k] = rgba[i + 1] / peak - 0.5 + input[plane * 2 + k] = rgba[i + 2] / peak - 0.5 + } + const outputs = await s.run({ + [s.inputNames[0]]: new ort.Tensor('float32', input, [1, 3, 1024, 1024]), + }) + const pred = outputs[s.outputNames[0]].data + let lo = Infinity + let hi = -Infinity + for (let k = 0; k < plane; k++) { + lo = Math.min(lo, pred[k]) + hi = Math.max(hi, pred[k]) + } + const range = hi - lo || 1 + const alpha = new Uint8ClampedArray(plane) + for (let k = 0; k < plane; k++) alpha[k] = ((pred[k] - lo) / range) * 255 + const mask = cleanCutout(alpha, 1024) + await s.release() + + let minX = image.width + let minY = image.height + let maxX = 0 + let maxY = 0 + const step = 4 + for (let y = 0; y < image.height; y += step) { + for (let x = 0; x < image.width; x += step) { + if (sampleMask(mask, 1024, x, y, image.width, image.height) < 32) continue + minX = Math.min(minX, x) + minY = Math.min(minY, y) + maxX = Math.max(maxX, x) + maxY = Math.max(maxY, y) + } + } + const padX = Math.round((maxX - minX) * 0.08) + const padY = Math.round((maxY - minY) * 0.06) + const crop = { + x: Math.max(0, minX - padX), + y: Math.max(0, minY - padY), + w: Math.min(image.width, maxX + padX) - Math.max(0, minX - padX), + h: Math.min(image.height, maxY + padY) - Math.max(0, minY - padY), + } + // The mask runs into the foreground leaves. The still shows the tower, where + // the removed sky is the result, and stops 1.2 widths down from the spire. + crop.h = Math.min(crop.h, Math.round(crop.w * 1.2)) + const maxW = 900 + const scale = Math.min(1, maxW / crop.w) + const outW = Math.round(crop.w * scale) + const outH = Math.round(crop.h * scale) + const full = createCanvas(image.width, image.height) + const fctx = full.getContext('2d') + fctx.drawImage(image, 0, 0) + const src = fctx.getImageData(crop.x, crop.y, crop.w, crop.h) + const fitted = await resizeRgba(src.data, crop.w, crop.h, outW, outH) + const cut = new Uint8ClampedArray(fitted) + for (let y = 0; y < outH; y++) { + for (let x = 0; x < outW; x++) { + const sx = crop.x + ((x + 0.5) * crop.w) / outW - 0.5 + const sy = crop.y + ((y + 0.5) * crop.h) / outH - 0.5 + cut[(y * outW + x) * 4 + 3] = sampleMask(mask, 1024, sx, sy, image.width, image.height) + } + } + await writeStill('cutout-before', fitted, outW, outH) + await writeStill('cutout-after', cut, outW, outH) + console.log('cutout crop', crop) +} + +async function removePeople() { + const image = await loadImage(PAGODA) + const sw = image.width + const sh = image.height + // Centres read off a 2× crop. The source sits on open gravel, up and to the left. + // The figure on the open gravel. The second figure stands against the eaves, + // and a gravel source leaves a dark patch there, so this still heals one person. + const spots = [ + { id: 'pagoda-person-a', x: 978, y: 2024 }, + ].map((p) => ({ + id: p.id, + mode: 'heal', + points: [p.x / sw, p.y / sh], + size: 0.022, + feather: 0.55, + opacity: 1, + dx: -110 / sw, + dy: -70 / sh, + })) + + // Wide enough that the heal source (about 110 px left and 70 px up) is inside the buffer. + const view = { x: 760, y: 1780, w: 500, h: 400 } + const viewCanvas = createCanvas(view.w, view.h) + const vctx = viewCanvas.getContext('2d') + vctx.drawImage(image, view.x, view.y, view.w, view.h, 0, 0, view.w, view.h) + const before = vctx.getImageData(0, 0, view.w, view.h) + const after = vctx.getImageData(0, 0, view.w, view.h) + applyHeal( + { + data: after.data, + width: view.w, + height: view.h, + stride: 4, + max: 255, + left: view.x, + top: view.y, + fullWidth: sw, + fullHeight: sh, + }, + spots, + ) + const outW = 840 + const outH = Math.round((view.h * outW) / view.w) + await writeStill('remove-before', await resizeRgba(before.data, view.w, view.h, outW, outH), outW, outH) + await writeStill('remove-after', await resizeRgba(after.data, view.w, view.h, outW, outH), outW, outH) +} + +const TILE = 128 +const PAD = 8 +const SCALE = 4 + +function tileStarts(length) { + if (length <= TILE) return [0] + const starts = [] + for (let pos = 0; pos + TILE < length; pos += TILE - 2 * PAD) starts.push(pos) + starts.push(length - TILE) + return starts +} + +function samplePlane(plane, offset, size, x, y) { + const fx = Math.min(size - 1, Math.max(0, x)) + const fy = Math.min(size - 1, Math.max(0, y)) + const x0 = Math.floor(fx) + const y0 = Math.floor(fy) + const x1 = Math.min(size - 1, x0 + 1) + const y1 = Math.min(size - 1, y0 + 1) + const tx = fx - x0 + const ty = fy - y0 + const top = plane[offset + y0 * size + x0] + (plane[offset + y0 * size + x1] - plane[offset + y0 * size + x0]) * tx + const bottom = plane[offset + y1 * size + x0] + (plane[offset + y1 * size + x1] - plane[offset + y1 * size + x0]) * tx + return top + (bottom - top) * ty +} + +/** Same tile loop as src/lib/upscale.worker.ts, then the 20% texture mix from upscale.ts. */ +async function upscaleFactor(rgba, width, height, factor, smooth) { + const s = await session(UPSCALE) + const ow = Math.round(width * factor) + const oh = Math.round(height * factor) + const out = new Uint8ClampedArray(ow * oh * 4) + const xs = tileStarts(width) + const ys = tileStarts(height) + const plane = TILE * TILE + const input = new Float32Array(plane * 3) + const big = TILE * SCALE + const bigPlane = big * big + const subs = Math.min(3, Math.max(1, Math.ceil(SCALE / factor - 0.25))) + for (const [yi, ty] of ys.entries()) { + for (const [xi, tx] of xs.entries()) { + for (let y = 0; y < TILE; y++) { + const sy = Math.min(height - 1, ty + y) + for (let x = 0; x < TILE; x++) { + const i = (sy * width + Math.min(width - 1, tx + x)) * 4 + const k = y * TILE + x + input[k] = rgba[i] / 255 + input[plane + k] = rgba[i + 1] / 255 + input[plane * 2 + k] = rgba[i + 2] / 255 + } + } + const outputs = await s.run({ image: new ort.Tensor('float32', input, [1, 3, TILE, TILE]) }) + const result = outputs.upscaled_image.data + const cx0 = xi === 0 ? 0 : tx + PAD + const cx1 = xi === xs.length - 1 ? width : tx + TILE - PAD + const cy0 = yi === 0 ? 0 : ty + PAD + const cy1 = yi === ys.length - 1 ? height : ty + TILE - PAD + const X0 = Math.max(0, Math.ceil(cx0 * factor - 0.5)) + const X1 = Math.min(ow, Math.ceil(cx1 * factor - 0.5)) + const Y0 = Math.max(0, Math.ceil(cy0 * factor - 0.5)) + const Y1 = Math.min(oh, Math.ceil(cy1 * factor - 0.5)) + for (let Y = Y0; Y < Y1; Y++) { + for (let X = X0; X < X1; X++) { + let r = 0 + let g = 0 + let b = 0 + for (let sy = 0; sy < subs; sy++) { + const qy = ((Y + (sy + 0.5) / subs) / factor - ty) * SCALE - 0.5 + for (let sx = 0; sx < subs; sx++) { + const qx = ((X + (sx + 0.5) / subs) / factor - tx) * SCALE - 0.5 + r += samplePlane(result, 0, big, qx, qy) + g += samplePlane(result, bigPlane, big, qx, qy) + b += samplePlane(result, bigPlane * 2, big, qx, qy) + } + } + const n = subs * subs + const o = (Y * ow + X) * 4 + out[o] = (r / n) * 255 + out[o + 1] = (g / n) * 255 + out[o + 2] = (b / n) * 255 + out[o + 3] = 255 + } + } + } + } + await s.release() + const TEXTURE_MIX = 0.2 + for (let i = 0; i < out.length; i += 4) { + out[i] = out[i] * (1 - TEXTURE_MIX) + smooth[i] * TEXTURE_MIX + out[i + 1] = out[i + 1] * (1 - TEXTURE_MIX) + smooth[i + 1] * TEXTURE_MIX + out[i + 2] = out[i + 2] * (1 - TEXTURE_MIX) + smooth[i + 2] * TEXTURE_MIX + out[i + 3] = 255 + } + return out +} + +async function upscale() { + console.log('upscale…') + const image = await loadImage(PAGODA) + // Eaves and vent under the spire: a 640×480 crop, then a long edge of 256. + const crop = { x: 1000, y: 980, w: 600, h: 450 } + const canvas = createCanvas(crop.w, crop.h) + const ctx = canvas.getContext('2d') + ctx.drawImage(image, crop.x, crop.y, crop.w, crop.h, 0, 0, crop.w, crop.h) + const full = ctx.getImageData(0, 0, crop.w, crop.h) + const smallW = 256 + const smallH = Math.round((crop.h * smallW) / crop.w) + const small = await resizeRgba(full.data, crop.w, crop.h, smallW, smallH) + const factor = 2 + const outW = smallW * factor + const outH = smallH * factor + const smooth = await resizeRgba(small, smallW, smallH, outW, outH) + const ai = await upscaleFactor(small, smallW, smallH, factor, smooth) + await writeStill('upscale-before', smooth, outW, outH) + await writeStill('upscale-after', ai, outW, outH) +} + +async function carousel() { + const image = await loadImage(APOSTLES) + const slideW = 540 + const slideH = 675 + const frame = { id: 'panorama', x: 0, y: 0, w: 3, h: 1, fx: 0.5, fy: 0.5, zoom: 1, rotate: 0 } + for (let i = 0; i < 3; i++) { + const canvas = createCanvas(slideW, slideH) + const ctx = canvas.getContext('2d') + ctx.fillStyle = '#0c100e' + ctx.fillRect(0, 0, slideW, slideH) + paintCarouselSlide(ctx, slideW, slideH, [frame], i, () => image) + const pixels = ctx.getImageData(0, 0, slideW, slideH) + await writeStill(`carousel-${i + 1}`, pixels.data, slideW, slideH) + } + const srcW = 960 + const srcH = Math.round((image.height * srcW) / image.width) + const src = createCanvas(image.width, image.height) + src.getContext('2d').drawImage(image, 0, 0) + const raw = src.getContext('2d').getImageData(0, 0, image.width, image.height) + await writeStill('carousel-source', await resizeRgba(raw.data, image.width, image.height, srcW, srcH), srcW, srcH) +} + +await mkdir(OUT, { recursive: true }) +const only = process.argv.includes('--only') ? process.argv[process.argv.indexOf('--only') + 1] : '' +if (!only || only === 'develop') await develop() +if (!only || only === 'cutout') await cutout() +if (!only || only === 'remove') await removePeople() +if (!only || only === 'upscale') await upscale() +if (!only || only === 'carousel') await carousel() +console.log(JSON.stringify(manifest, null, 2)) +console.log('done') diff --git a/scripts/register-ts.mjs b/scripts/register-ts.mjs new file mode 100644 index 0000000..e9cfc1c --- /dev/null +++ b/scripts/register-ts.mjs @@ -0,0 +1,3 @@ +import { register } from 'node:module' + +register('./ts-resolve-hook.mjs', new URL('./', import.meta.url).href) diff --git a/scripts/result-stills.test.mjs b/scripts/result-stills.test.mjs new file mode 100644 index 0000000..8fb77b3 --- /dev/null +++ b/scripts/result-stills.test.mjs @@ -0,0 +1,35 @@ +import assert from 'node:assert/strict' +import { readFile } from 'node:fs/promises' +import { test } from 'node:test' +import sharp from 'sharp' + +/** Files the home and tool pages point at. Dimensions are the ones written into src/site/results.ts. */ +const STILLS = { + 'develop-before': [1200, 801], + 'develop-after': [1200, 801], + 'cutout-before': [731, 877], + 'cutout-after': [731, 877], + 'remove-before': [840, 672], + 'remove-after': [840, 672], + 'upscale-before': [512, 384], + 'upscale-after': [512, 384], + 'carousel-source': [960, 640], + 'carousel-1': [540, 675], + 'carousel-2': [540, 675], + 'carousel-3': [540, 675], +} + +test('result stills exist as webp and avif at the documented size', async () => { + for (const [name, [width, height]] of Object.entries(STILLS)) { + for (const ext of ['webp', 'avif']) { + const path = `public/site/results/${name}.${ext}` + const bytes = await readFile(path) + assert.ok(bytes.length > 500, path) + const meta = await sharp(bytes).metadata() + assert.equal(meta.width, width, path) + assert.equal(meta.height, height, path) + } + } + const cutout = await sharp('public/site/results/cutout-after.webp').stats() + assert.ok(cutout.channels[3].min < 10, 'cutout after keeps a transparent background') +}) diff --git a/scripts/ts-resolve-hook.mjs b/scripts/ts-resolve-hook.mjs new file mode 100644 index 0000000..90e6ff4 --- /dev/null +++ b/scripts/ts-resolve-hook.mjs @@ -0,0 +1,14 @@ +/** + * Resolve extensionless imports in src/*.ts when the result stills script + * loads the editor's own modules under node --experimental-strip-types. + */ +export async function resolve(specifier, context, nextResolve) { + if ((specifier.startsWith('.') || specifier.startsWith('/')) && !/\.(?:js|mjs|cjs|ts|json|node|wasm)$/.test(specifier)) { + try { + return await nextResolve(`${specifier}.ts`, context) + } catch { + return nextResolve(`${specifier}.js`, context) + } + } + return nextResolve(specifier, context) +} diff --git a/src/lib/cutout.ts b/src/lib/cutout.ts index 1b78b08..4312f6b 100644 --- a/src/lib/cutout.ts +++ b/src/lib/cutout.ts @@ -48,7 +48,7 @@ const SUBJECT_MARGIN = 12 * foliage): keep the solid regions of subject size, plus a soft margin * around them, and clear everything else. */ -function cleanCutout(alpha: Uint8ClampedArray, n: number): Uint8ClampedArray { +export function cleanCutout(alpha: Uint8ClampedArray, n: number): Uint8ClampedArray { const labels = new Int32Array(n * n).fill(-1) const sizes: number[] = [] const stack = new Int32Array(n * n) diff --git a/src/site/components/BeforeAfter.astro b/src/site/components/BeforeAfter.astro new file mode 100644 index 0000000..b4e296f --- /dev/null +++ b/src/site/components/BeforeAfter.astro @@ -0,0 +1,39 @@ +--- +/** + * Side-by-side stills, same pattern as the free-presets pack: a figure, a + * caption under it, several of them in a row. + */ +import type { Still } from '../results' + +interface Props { + shots: Still[] + caption?: string +} + +const { shots, caption } = Astro.props +--- + +
+
+ { + shots.map((shot) => ( +
+ + + {shot.alt} + +
{shot.label}
+
+ )) + } +
+ {caption &&

{caption}

} +
diff --git a/src/site/landing.ts b/src/site/landing.ts index 7f12eee..56ac625 100644 --- a/src/site/landing.ts +++ b/src/site/landing.ts @@ -13,6 +13,14 @@ export const landing = { h1: 'The open-source photo editor that stays on your device', lead: 'Apply your own presets, Lightroom XMP files and .cube LUTs across a whole shoot, then export an Instagram-ready carousel. It all runs in the browser. Nothing is uploaded.', secondary: 'How it works', + cta: 'Open the editor — no sign-up', + promise: 'No uploads. It runs in this tab.', + heroCaption: 'twelve-apostles.jpg after exposure, colour and clarity. The before is with the examples below.', + heroAlt: 'Twelve Apostles sea stacks after exposure and colour adjustments in Lightframes', + results: { + h2: 'Before and after, from the sample photos', + lead: 'These are the sample photos shipped with the editor, processed with the same code. Nothing here is a mockup.', + }, facts: ['Free and open source', 'Presets, XMP and LUTs', 'Nothing uploaded'], video: { label: 'Lightframes in action: editing, presets, batch export, AI tools and collages', @@ -68,6 +76,14 @@ export const landing = { h1: 'El editor de fotos open source que se queda en tu dispositivo', lead: 'Aplica tus presets, archivos XMP de Lightroom y LUTs .cube a toda una sesión y exporta un carrusel listo para Instagram. Todo ocurre en el navegador. No se sube nada.', secondary: 'Cómo funciona', + cta: 'Abrir el editor — sin registro', + promise: 'Sin subir archivos. Se ejecuta en esta pestaña.', + heroCaption: 'twelve-apostles.jpg tras exposición, color y claridad. El antes está con los ejemplos de abajo.', + heroAlt: 'Los stacks de los Twelve Apostles tras ajustar exposición y color en Lightframes', + results: { + h2: 'Antes y después, con las fotos de ejemplo', + lead: 'Son las fotos de ejemplo que trae el editor, procesadas con el mismo código. No hay maquetas.', + }, facts: ['Gratis y de código abierto', 'Presets, XMP y LUTs', 'Sin subir nada'], video: { label: 'Lightframes en acción: edición, presets, exportación por lotes, herramientas de IA y collages', diff --git a/src/site/results.ts b/src/site/results.ts new file mode 100644 index 0000000..1ebab1d --- /dev/null +++ b/src/site/results.ts @@ -0,0 +1,236 @@ +import type { Lang } from './i18n' + +export interface Still { + /** WebP fallback. */ + src: string + avif: string + width: number + height: number + alt: string + label: string + /** Draw a checkerboard behind the pixels so a transparent background reads as empty. */ + transparent?: boolean + /** Above-the-fold result. Preload the AVIF separately; this only sets fetch priority. */ + priority?: boolean +} + +/** + * Stills in public/site/results/, produced by scripts/build-result-stills.mjs + * from public/samples/. The captions say what was actually done. + */ + +const SRC = '/site/results' + +function still( + name: string, + width: number, + height: number, + alt: string, + label: string, + extra: Partial = {}, +): Still { + return { + src: `${SRC}/${name}.webp`, + avif: `${SRC}/${name}.avif`, + width, + height, + alt, + label, + ...extra, + } +} + +export interface ResultExample { + /** Tool `key`, when the example belongs on that tool page. */ + toolKey: string + href: string + title: string + caption: string + shots: Still[] +} + +const PATHS: Record> = { + en: { + 'raw-to-jpg': '/tools/raw-to-jpg', + 'background-remover': '/tools/background-remover', + 'remove-objects': '/tools/remove-objects-from-photos', + upscaler: '/tools/ai-image-upscaler', + carousel: '/tools/instagram-carousel-maker', + }, + es: { + 'raw-to-jpg': '/es/herramientas/convertir-raw-a-jpg', + 'background-remover': '/es/herramientas/quitar-fondo-foto', + 'remove-objects': '/es/herramientas/borrar-objetos-foto', + upscaler: '/es/herramientas/ampliar-foto-ia', + carousel: '/es/herramientas/carrusel-instagram', + }, +} + +export function resultExamples(lang: Lang): ResultExample[] { + const en = lang === 'en' + const before = en ? 'Before' : 'Antes' + const after = en ? 'After' : 'Después' + const href = PATHS[lang] + return [ + { + toolKey: 'raw-to-jpg', + href: href['raw-to-jpg'], + title: en ? 'Develop, then export' : 'Revelar y exportar', + caption: en + ? 'Before is public/samples/twelve-apostles.jpg, the flat JPEG shipped with the editor (developed flat from the author’s RAW; that RAW file is not in the repo). After is the same JPEG through the editor’s develop pipeline: exposure +0.85, contrast +26, highlights −65, shadows +85, whites +25, blacks −20, temperature +22, vibrance +55, saturation +8, clarity +32, dehaze +30.' + : 'Antes es public/samples/twelve-apostles.jpg, el JPEG plano que trae el editor (revelado plano a partir del RAW del autor; ese RAW no está en el repositorio). Después es el mismo JPEG pasado por el revelado del editor: exposición +0,85, contraste +26, altas luces −65, sombras +85, blancos +25, negros −20, temperatura +22, intensidad +55, saturación +8, claridad +32, dehaze +30.', + shots: [ + still( + 'develop-before', + 1200, + 801, + en + ? 'Twelve Apostles sea stacks, the flat sample JPEG before adjustments' + : 'Los Twelve Apostles, el JPEG de ejemplo plano, antes de los ajustes', + before, + ), + still( + 'develop-after', + 1200, + 801, + en + ? 'The same Twelve Apostles photo after exposure, colour and clarity in Lightframes' + : 'La misma foto de los Twelve Apostles tras exposición, color y claridad en Lightframes', + after, + ), + ], + }, + { + toolKey: 'background-remover', + href: href['background-remover'], + title: en ? 'Background removed' : 'Fondo quitado', + caption: en + ? 'A crop of public/samples/pagoda.jpg. After uses the IS-Net subject mask shipped in public/models, cleaned with the editor’s speck filter, and keeps the background transparent. The checkerboard is not part of the photo. The crop is the tower; the same mask also keeps some leaves lower in the frame.' + : 'Un recorte de public/samples/pagoda.jpg. Después usa la máscara de sujeto IS-Net que va en public/models, limpia con el filtro de motas del editor, y deja el fondo transparente. El damero no forma parte de la foto. El recorte es la torre; la misma máscara también conserva algunas hojas más abajo.', + shots: [ + still( + 'cutout-before', + 731, + 877, + en ? 'Pagoda tower against a cloudy sky, before background removal' : 'Torre de la pagoda contra un cielo nublado, antes de quitar el fondo', + before, + ), + still( + 'cutout-after', + 731, + 877, + en + ? 'The same pagoda crop with the sky removed and a transparent background' + : 'El mismo recorte de la pagoda con el cielo quitado y el fondo transparente', + after, + { transparent: true }, + ), + ], + }, + { + toolKey: 'remove-objects', + href: href['remove-objects'], + title: en ? 'Person healed out' : 'Persona eliminada con el parche', + caption: en + ? 'A crop of public/samples/pagoda.jpg. After is one Heal spot on the person standing on the gravel: brush radius about 53 px on the long edge, copying gravel from 110 px left and 70 px up, then blended by the editor’s Heal code. The brush also reaches the second person, who stands against the eaves, so that edge stays soft. An inpaint of these figures filled the hole with leaves, so this still is the Heal result.' + : 'Un recorte de public/samples/pagoda.jpg. Después es un parche Heal sobre la persona que está en la grava: radio de unos 53 px en el lado largo, copiando grava desde 110 px a la izquierda y 70 px arriba, y mezclado con el código Heal del editor. El pincel también alcanza a la segunda persona, que está contra el alero, así que ese borde queda suave. Un relleno por IA de estas figuras cubrió el hueco con hojas, así que este ejemplo es el resultado de Heal.', + shots: [ + still( + 'remove-before', + 840, + 672, + en + ? 'Two people on the gravel path under the pagoda eaves, before healing' + : 'Dos personas en el camino de grava bajo el alero de la pagoda, antes del parche', + before, + ), + still( + 'remove-after', + 840, + 672, + en + ? 'The same crop after Heal copies nearby gravel over the person on the path' + : 'El mismo recorte después de que Heal copia la grava cercana sobre la persona del camino', + after, + ), + ], + }, + { + toolKey: 'upscaler', + href: href.upscaler, + title: en ? '2× upscale' : 'Ampliación 2×', + caption: en + ? 'A 600×450 crop of the pagoda roof in public/samples/pagoda.jpg, scaled down to 256 px on the long edge. Before enlarges that small crop 2× with a smooth resize. After is Real-ESRGAN (the model in public/models) at 2× on the same pixels, mixed with 20% of the smooth resize, which is what export does. It is not detail that was never in the file.' + : 'Un recorte de 600×450 del tejado de la pagoda en public/samples/pagoda.jpg, reducido a 256 px en el lado largo. Antes amplía ese recorte pequeño 2× con un reescalado suave. Después es Real-ESRGAN (el modelo de public/models) a 2× sobre los mismos píxeles, mezclado con un 20% del reescalado suave, que es lo que hace la exportación. No es detalle que no estuviera en el archivo.', + shots: [ + still( + 'upscale-before', + 512, + 384, + en + ? 'Pagoda roof crop enlarged 2× with a smooth resize from a 256 px source' + : 'Recorte del tejado de la pagoda ampliado 2× con un reescalado suave desde 256 px', + en ? 'Smooth resize' : 'Reescalado suave', + ), + still( + 'upscale-after', + 512, + 384, + en + ? 'The same roof crop enlarged 2× with Real-ESRGAN and a 20% smooth-resize mix' + : 'El mismo recorte del tejado ampliado 2× con Real-ESRGAN y un 20% de reescalado suave', + en ? 'Real-ESRGAN 2×' : 'Real-ESRGAN 2×', + ), + ], + }, + { + toolKey: 'carousel', + href: href.carousel, + title: en ? 'Three seamless slides' : 'Tres diapositivas continuas', + caption: en + ? 'public/samples/twelve-apostles.jpg in the Panorama layout: one photo across three 4:5 slides, cover-fit, painted by the editor’s carousel painter. Each slide is 540×675, half of the 1080×1350 export, so the crop is the export crop.' + : 'public/samples/twelve-apostles.jpg en la disposición Panorama: una foto a lo largo de tres diapositivas 4:5, en cover, pintadas con el pintor de carrusel del editor. Cada diapositiva es de 540×675, la mitad de la exportación a 1080×1350, así que el recorte es el de la exportación.', + shots: [ + still( + 'carousel-source', + 960, + 640, + en ? 'The full Twelve Apostles sample, before it is split into slides' : 'La foto completa de ejemplo de los Twelve Apostles, antes de dividirla', + en ? 'Source' : 'Origen', + ), + still( + 'carousel-1', + 540, + 675, + en ? 'Carousel slide 1 of 3, the left of the Twelve Apostles panorama' : 'Diapositiva 1 de 3 del carrusel, la izquierda de la panorámica', + en ? 'Slide 1' : 'Diapositiva 1', + ), + still( + 'carousel-2', + 540, + 675, + en ? 'Carousel slide 2 of 3, the middle of the Twelve Apostles panorama' : 'Diapositiva 2 de 3 del carrusel, el centro de la panorámica', + en ? 'Slide 2' : 'Diapositiva 2', + ), + still( + 'carousel-3', + 540, + 675, + en ? 'Carousel slide 3 of 3, the right of the Twelve Apostles panorama' : 'Diapositiva 3 de 3 del carrusel, la derecha de la panorámica', + en ? 'Slide 3' : 'Diapositiva 3', + ), + ], + }, + ] +} + +export function exampleForTool(toolKey: string, lang: Lang): ResultExample | undefined { + return resultExamples(lang).find((example) => example.toolKey === toolKey) +} + +/** The adjusted sample used as the hero result. Same file as the develop “after”. */ +export function heroResult(lang: Lang): Still { + const example = exampleForTool('raw-to-jpg', lang)! + const after = example.shots[1]! + return { ...after, label: lang === 'es' ? 'Resultado' : 'Result', priority: true } +} diff --git a/src/site/styles/site.css b/src/site/styles/site.css index 931f063..526894f 100644 --- a/src/site/styles/site.css +++ b/src/site/styles/site.css @@ -415,6 +415,21 @@ a { margin-top: 32px; } +.hero__promise { + margin: 14px 0 0; + font-size: 1.0625rem; + font-weight: 700; +} + +/* The label is the whole offer, so it can wrap instead of overflowing a narrow screen. */ +.hero .button--large { + white-space: normal; + text-align: center; + line-height: 1.25; + padding-block: 12px; + max-width: 100%; +} + .facts { display: flex; flex-wrap: wrap; @@ -460,15 +475,134 @@ a { } } +@media (max-width: 999px) { + /* Tagline, the editor button and the result stay on the first screen; the lead follows. */ + .hero { + display: flex; + flex-direction: column; + gap: 20px; + padding-bottom: 28px; + } + + .hero__text { + display: contents; + } + + .hero h1 { + order: 1; + } + + .hero__actions { + order: 2; + margin-top: 0; + } + + .hero__promise { + order: 3; + margin-top: 0; + } + + .hero__result { + order: 4; + } + + .hero .lead { + order: 5; + margin-top: 0; + } + + .hero .facts { + order: 6; + margin-top: 0; + } + + .hero__aside { + order: 7; + } +} + @media (min-width: 1000px) { .hero { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: center; gap: 56px; - padding-block: 64px 104px; + padding-block: 64px 48px; + } + + .hero__result .ba__shot { + flex-basis: 100%; } } +.promo-band { + padding-bottom: clamp(8px, 2vw, 24px); +} + +/* Before / after stills. Same idea as the free-presets pack: labeled frames in a row. */ + +.ba__frames { + display: flex; + flex-wrap: wrap; + gap: 12px; + align-items: flex-start; +} + +.ba__shot { + margin: 0; + flex: 1 1 200px; + min-width: min(100%, 200px); +} + +.ba__shot img { + display: block; + width: 100%; + height: auto; + border-radius: 12px; + border: 1px solid var(--line-strong); + background: var(--bg-panel); +} + +.ba__shot--alpha img { + background-color: #121816; + background-image: + linear-gradient(45deg, #243028 25%, transparent 25%), + linear-gradient(-45deg, #243028 25%, transparent 25%), + linear-gradient(45deg, transparent 75%, #243028 75%), + linear-gradient(-45deg, transparent 75%, #243028 75%); + background-size: 20px 20px; + background-position: + 0 0, + 0 10px, + 10px -10px, + -10px 0; +} + +.ba__shot figcaption { + margin-top: 6px; + font-size: 0.875rem; + color: var(--text-muted); +} + +.ba__note { + margin-top: 12px; + max-width: 72ch; + color: var(--text-muted); + font-size: 0.9375rem; +} + +.ba-block + .ba-block { + margin-top: 48px; +} + +.ba-block h3 { + margin-bottom: 12px; +} + +.ba-block h3 a { + color: inherit; + text-underline-offset: 3px; +} + /* Promo video */ .promo { diff --git a/src/site/views/LandingView.astro b/src/site/views/LandingView.astro index 193db89..3a93790 100644 --- a/src/site/views/LandingView.astro +++ b/src/site/views/LandingView.astro @@ -1,10 +1,12 @@ --- +import BeforeAfter from '../components/BeforeAfter.astro' import FaqList from '../components/FaqList.astro' import ToolList from '../components/ToolList.astro' import { SITE, absoluteUrl } from '../config' import { entryPath, getFaq, getPosts, getTools } from '../content' import { editorPath, formatDate, href, sectionAlternates, ui, type Lang } from '../i18n' import { landing } from '../landing' +import { heroResult, resultExamples } from '../results' import { xmpLandingPath } from '../xmpLanding' import Base from '../layouts/Base.astro' import { faqPage, publishingOrganization, videoObject, webApplication, webPage } from '../schema' @@ -22,6 +24,8 @@ const allTools = await getTools(lang) const tools = allTools.filter((tool) => tool.data.featured) const faq = (await getFaq(lang)).slice(0, 6) const posts = (await getPosts(lang)).slice(0, 3) +const hero = heroResult(lang) +const examples = resultExamples(lang) --- + +

{c.h1}

{c.lead}

+

{c.promise}

    {c.facts.map((fact) =>
  • {fact}
  • )}
@@ -68,6 +75,12 @@ const posts = (await getPosts(lang)).slice(0, 3)

+
+ +
+
+ +
+
+
+

{c.results.h2}

+

{c.results.lead}

+
+ { + examples.map((example) => ( + + )) + } +
+
diff --git a/src/site/views/ToolView.astro b/src/site/views/ToolView.astro index b79faf5..acba5e5 100644 --- a/src/site/views/ToolView.astro +++ b/src/site/views/ToolView.astro @@ -1,5 +1,6 @@ --- import { render } from 'astro:content' +import BeforeAfter from '../components/BeforeAfter.astro' import Breadcrumbs from '../components/Breadcrumbs.astro' import EditorCta from '../components/EditorCta.astro' import FaqList from '../components/FaqList.astro' @@ -8,6 +9,7 @@ import { absoluteUrl } from '../config' import { entryAlternates, entryPath, getTools, type Tool } from '../content' import { formatDate, href, langOf, ui } from '../i18n' import Base from '../layouts/Base.astro' +import { exampleForTool } from '../results' import { breadcrumbs, faqPage, howTo, publishingOrganization, webApplication, webPage } from '../schema' interface Props { @@ -25,6 +27,7 @@ const tools = await getTools(lang) const related = tools.filter((other) => other.data.featured && other.id !== tool.id).slice(0, 4) const editorQuery = data.key === 'raw-to-jpg' || data.key.endsWith('-to-jpg') ? '?intent=raw' : undefined +const example = exampleForTool(data.key, lang) const crumbs = [ { name: t.home, path: href('home', lang) }, { name: t.tools, path: href('tools', lang) }, @@ -56,6 +59,15 @@ const crumbs = [ + { + example && ( +
+

{lang === 'es' ? 'Un ejemplo real' : 'A real example'}

+ +
+ ) + } + { data.steps.length > 0 && (