Draw on the image view:
+
+
+
+
+ App ScreenshotAs the app shows it
+
+
+
+
Upload screenshotClick or drop
+
Click or drop to change
+
+
+
+ Image to injectGreen line = the subject
+
-
-
-
Turn
-
-
-
- 0°
-
-
+
+
+
+
Upload image to injectClick or drop a file: a document, face, QR code or any other image
+
Drag to mark the subject yourself
+
-
-
-
Size
-
-
92% of largest fit
-
Drag on the check view to move. Scroll to resize.
+
+
OutputThe file to inject. Grey = padding
+
-
-
-
-
-
-
-
-
-
-
-
-
1 · ScreenshotGreen line = viewfinder found
-
2 · Image to injectGreen line = subject. Drag to draw. Drag inside your shape to move it, scroll to resize
-
3 · OutputSame size as the screenshot. Grey = padding
-
4 · CheckOutput over the screenshot. Drag to move
-
-
-
-
+
+ The padded image shows here after both uploads.
+
✥ Drag to move · Scroll to resize
+
+
@@ -521,10 +776,11 @@
(() => {
const $ = (id) => document.getElementById(id);
const PAD = [128, 128, 128];
- const S = { cv: null, core: null, shot: null, img: null, vf: null, subj: null, cands: [], sel: 0, crop: null,
- rot90: 0, fine: 0, size: 0.92, cx: 0, cy: 0, base: 1, names: {}, mode: 'box', poly: null };
+ const S = { cv: null, core: null, shot: null, screen: null, cal: null, vf0: null, img: null, imgName: '', vf: null, subj: null, cands: [], sel: 0, crop: null,
+ rot90: 0, fine: 0, size: 0.92, cx: 0, cy: 0, base: 1, mode: 'box', poly: null };
- const setMsg = (t) => { $('msg').textContent = t || ''; };
+ let note = '';
+ const setMsg = (t) => { note = t || ''; status(); };
const engine = (t, ok) => { $('engineText').textContent = t; $('engine').classList.toggle('ready', !!ok); };
function loadScript(src) {
@@ -544,7 +800,7 @@
const b64 = (await (await fetch('u2netp.onnx.b64.txt')).text()).trim(); const bin = atob(b64); const model = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) model[i] = bin.charCodeAt(i);
S.cv = cv; S.core = PadFitCore(cv, ort, model);
engine('Ready', true);
- await loadExample();
+ if (S.shot || S.img) await analyse(S.img ? 'img' : 'shot');
} catch (e) { engine('Engine failed'); setMsg(e.message + '. Reload the page to try again.'); }
}
@@ -556,47 +812,69 @@
c.getContext('2d').drawImage(bmp, 0, 0, c.width, c.height); bmp.close && bmp.close();
return c;
}
- async function setInput(kind, blob, name, isExample) {
+ async function setInput(kind, blob, name) {
let c;
try { c = await toCanvas(blob, kind === 'img' ? 2560 : 0); }
catch { setMsg('That file is not an image this browser can read. Use PNG or JPEG.'); return; }
- const url = c.toDataURL('image/jpeg', 0.6);
- if (kind === 'shot') { S.shot = c; $('thumbShot').src = url; $('nameShot').textContent = name; }
- else { S.img = c; $('thumbImg').src = url; $('nameImg').textContent = name; }
- if (!isExample) $('exampleTag').hidden = true;
+ if (kind === 'shot') { S.shot = c; $('wellShot').classList.add('has'); $('wellShot').setAttribute('aria-label', 'Change app screenshot'); }
+ else { S.img = c; S.imgName = name; S.subj = null; $('wellImg').classList.add('has'); $('changeImg').hidden = false; }
+ saved = false;
setMsg('');
await analyse(kind);
}
- async function loadExample() {
+ $('example').addEventListener('click', async () => {
const [a, b] = await Promise.all(['example-screen.png', 'example-image.png'].map(async (f) => (await fetch(f)).blob()));
- $('exampleTag').hidden = false;
- await setInput('shot', a, 'Example: test app, tint window', true);
- await setInput('img', b, 'Example: QR on a desk', true);
- }
- for (const [k, drop, file] of [['shot', 'dropShot', 'fileShot'], ['img', 'dropImg', 'fileImg']]) {
- const d = $(drop), f = $(file);
- f.addEventListener('change', () => f.files[0] && setInput(k, f.files[0], f.files[0].name));
+ await setInput('shot', a, 'example screen');
+ await setInput('img', b, 'example-qr');
+ setMsg('Example loaded: a normal screenshot of a test app and a QR code on a desk.');
+ });
+ for (const [k, well, file] of [['shot', 'wellShot', 'fileShot'], ['img', 'wellImg', 'fileImg']]) {
+ const d = $(well), f = $(file);
+ f.addEventListener('change', () => { if (f.files[0]) setInput(k, f.files[0], f.files[0].name); f.value = ''; });
+ d.addEventListener('click', () => { if (k === 'shot' || !S.img) f.click(); });
d.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); f.click(); } });
d.addEventListener('dragover', (e) => { e.preventDefault(); d.classList.add('over'); });
d.addEventListener('dragleave', () => d.classList.remove('over'));
d.addEventListener('drop', (e) => { e.preventDefault(); d.classList.remove('over'); const x = e.dataTransfer.files[0]; if (x) setInput(k, x, x.name); });
}
+ $('changeImg').addEventListener('click', () => $('fileImg').click());
// ---------- analysis ----------
+ const outSize = () => (S.cal ? S.core.GRID_SIZE : [S.shot.width, S.shot.height]);
+ function dropViewfinder() {
+ if (S.vf && S.vf !== S.vf0) S.vf.mask.delete();
+ if (S.vf0) S.vf0.mask.delete();
+ S.vf = S.vf0 = null; S.cal = null;
+ }
async function analyse(kind) {
if (!S.core) return;
const cv = S.cv;
try {
- if ((kind === 'shot' || !S.vf) && S.shot) {
- if (S.vf) S.vf.mask.delete();
- const m = cv.imread(S.shot); S.vf = S.core.viewfinder(m); m.delete();
+ if (kind === 'shot' && S.shot) {
+ dropViewfinder();
+ const raw = cv.imread(S.shot); const screen = S.core.screenRect(raw); raw.delete();
+ S.screen = screen;
+ const notes = [];
+ if (screen) {
+ const [x, y, w, h] = screen, c = document.createElement('canvas'); c.width = w; c.height = h;
+ c.getContext('2d').drawImage(S.shot, x, y, w, h, 0, 0, w, h);
+ S.shot = c; notes.push('Removed the phone frame around the screenshot.');
+ }
+ const m = cv.imread(S.shot); const a = S.core.analyseShot(m); m.delete();
+ S.vf0 = a.vf; S.cal = a.cal;
+ if (S.cal) {
+ const [GW, GH] = S.core.GRID_SIZE;
+ S.vf = S.core.mapViewfinder(S.vf0, S.cal, GW, GH);
+ const [, y0, , y1] = S.cal.window_frac;
+ notes.push(`Calibration image found: the viewfinder shows ${Math.round(y0 * 100)}% to ${Math.round(y1 * 100)}% of the image height. The output puts the subject there.`);
+ } else S.vf = S.vf0;
+ setMsg(notes.join(' '));
}
- if ((kind === 'img' || !S.subj) && S.img) {
+ if (kind === 'img' && S.img) {
engine('Finding subject…');
const m = cv.imread(S.img); const s = await S.core.subject(m); m.delete();
engine('Ready', true);
S.subj = s;
- const W = S.img.width, H = S.img.height;
const seen = []; S.cands = [];
const add = (b, label) => { if (seen.some((x) => S.core.iou(x, b) > 0.9)) return; seen.push(b); S.cands.push({ b, label }); };
if (s.chosen) add(s.chosen, 'Auto · ' + nice(s.chosen.kind));
@@ -606,10 +884,48 @@
buildChips(); makeCrop();
S.rot90 = 0; S.fine = 0; S.size = 0.92; syncControls();
}
- if (S.shot && S.img) autoFit();
+ if (S.vf && S.crop) autoFit();
} catch (e) { engine('Ready', true); setMsg('Analysis failed: ' + e.message); }
renderAll();
}
+ // Inside a claude.ai artifact a link download is blocked, so use its downloads capability there.
+ async function saveBlob(blob, filename) {
+ const dl = window.claude && window.claude.use ? await window.claude.use('downloads') : null;
+ if (dl) { await dl.save({ filename, data: blob }); return; }
+ const url = URL.createObjectURL(blob), a = document.createElement('a');
+ a.href = url; a.download = filename; a.style.display = 'none';
+ document.body.appendChild(a); a.click(); a.remove();
+ setTimeout(() => URL.revokeObjectURL(url), 10000);
+ }
+ const GRID_SIZE = [1080, 1920], GRID_STEP = 0.1;
+ // Same pixels as core.calibrationGrid, drawn without OpenCV so it works before the engine loads.
+ function calibrationGrid() {
+ const [W, H] = GRID_SIZE, c = document.createElement('canvas'); c.width = W; c.height = H;
+ const ctx = c.getContext('2d'), img = ctx.createImageData(W, H), d = img.data;
+ for (let y = 0; y < H; y++) {
+ const r = Math.round(255 * y / (H - 1));
+ for (let x = 0; x < W; x++) {
+ const i = 4 * (y * W + x);
+ d[i] = r; d[i + 1] = Math.round(255 * x / (W - 1)); d[i + 2] = 255; d[i + 3] = 255;
+ }
+ }
+ ctx.putImageData(img, 0, 0);
+ const lw = Math.max(4, Math.round(0.012 * Math.min(W, H))), half = Math.floor(lw / 2), font = Math.min(W, H) / 900;
+ ctx.fillStyle = '#000'; ctx.font = `${Math.round(28 * font)}px Arial, sans-serif`;
+ for (let k = 1; k * GRID_STEP < 1 - 1e-9; k++) {
+ const y = Math.round(k * GRID_STEP * H), x = Math.round(k * GRID_STEP * W);
+ ctx.fillRect(0, y - half, W, lw); ctx.fillRect(x - half, 0, lw, H);
+ for (const lx of [0.02, 0.52]) ctx.fillText(`${k * 10}%`, Math.round(lx * W), y - 2 * lw);
+ }
+ return c;
+ }
+ const downloadGrid = () => {
+ gridSaved = true; steps();
+ const c = calibrationGrid();
+ c.toBlob((b) => saveBlob(b, `image-padding-calibration_${c.width}x${c.height}.png`).catch((e) => setMsg(e && e.code === 'declined' ? '' : 'Download failed: ' + (e && e.message || e))), 'image/png');
+ };
+ $('gridBtn').addEventListener('click', downloadGrid); $('gridAgain').addEventListener('click', downloadGrid);
+ $('haveShot').addEventListener('click', () => { shotTaken = true; steps(); });
const nice = (k) => ({ foreground: 'Foreground', saliency: 'Salient area', document: 'Document', manual: 'Your box', lasso: 'Your shape', whole: 'Whole image' }[k] || k);
function buildChips() {
@@ -635,15 +951,13 @@
ctx.drawImage(S.img, -x0, -y0); S.crop = cnv; return;
}
const m = cv.imread(S.img);
- let out;
- if (c.kind === 'whole') out = m.clone();
- else out = S.core.cropTo(m, c, c.kind === 'manual' ? 0 : 0.05);
+ const out = c.kind === 'whole' ? m.clone() : S.core.cropTo(m, c, c.kind === 'manual' ? 0 : 0.05);
const cnv = document.createElement('canvas'); cv.imshow(cnv, out);
m.delete(); out.delete();
S.crop = cnv;
}
- // ---------- placement ----------
+ // ---------- placement (all in output pixels) ----------
const angle = () => S.rot90 * 90 + S.fine;
function bbox(w, h, deg) { const a = deg * Math.PI / 180, c = Math.abs(Math.cos(a)), s = Math.abs(Math.sin(a)); return [w * c + h * s, w * s + h * c]; }
function autoFit() {
@@ -677,37 +991,55 @@
}
return true;
}
+ // Screenshot pixels per output pixel. With calibration the app shows image fraction a + s * p at screen pixel p.
+ function screenFromOutput() {
+ if (!S.cal) return { kx: 1, ky: 1, ox: 0, oy: 0 };
+ const [W, H] = outSize(), c = S.cal;
+ return { kx: 1 / (c.x.s * W), ky: 1 / (c.y.s * H), ox: -c.x.a / c.x.s, oy: -c.y.a / c.y.s };
+ }
// ---------- rendering ----------
+ const guide = () => getComputedStyle(document.documentElement).getPropertyValue('--guide').trim() || '#19c25c';
function drawSubject(ctx, alpha) {
const w = S.crop.width * S.base * S.size, h = S.crop.height * S.base * S.size;
ctx.save(); ctx.globalAlpha = alpha; ctx.translate(S.cx, S.cy); ctx.rotate(angle() * Math.PI / 180);
ctx.imageSmoothingQuality = 'high'; ctx.drawImage(S.crop, -w / 2, -h / 2, w, h); ctx.restore();
}
- function outline(ctx, lw) {
- const h = S.vf.hull; if (!h || h.length < 6) return;
- ctx.save(); ctx.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--guide').trim() || '#19c25c';
- ctx.lineWidth = lw; ctx.beginPath(); ctx.moveTo(h[0], h[1]);
- for (let i = 2; i < h.length; i += 2) ctx.lineTo(h[i], h[i + 1]);
- ctx.closePath(); ctx.stroke(); ctx.restore();
+ function hullPath(ctx, h) { ctx.beginPath(); ctx.moveTo(h[0], h[1]); for (let i = 2; i < h.length; i += 2) ctx.lineTo(h[i], h[i + 1]); ctx.closePath(); }
+ function outline(ctx, lw, vf) {
+ const h = vf.hull; if (!h || h.length < 6) return;
+ ctx.save(); ctx.strokeStyle = guide(); ctx.lineWidth = lw; hullPath(ctx, h); ctx.stroke(); ctx.restore();
}
function renderOutput(c) {
- c.width = S.shot.width; c.height = S.shot.height;
+ [c.width, c.height] = outSize();
const ctx = c.getContext('2d'); ctx.fillStyle = `rgb(${PAD.join(',')})`; ctx.fillRect(0, 0, c.width, c.height);
if (S.crop) drawSubject(ctx, 1);
}
+ // The check view shows the subject the way the app shows it: dim outside the viewfinder, clear inside it.
+ function renderCheck(c, lw) {
+ c.width = S.shot.width; c.height = S.shot.height; const x = c.getContext('2d');
+ x.drawImage(S.shot, 0, 0);
+ const t = screenFromOutput(), toScreen = () => x.setTransform(t.kx, 0, 0, t.ky, t.ox, t.oy);
+ x.save(); toScreen(); drawSubject(x, 0.3); x.restore();
+ const h = S.vf0.hull;
+ if (h && h.length >= 6) { x.save(); hullPath(x, h); x.clip(); toScreen(); drawSubject(x, 0.95); x.restore(); }
+ outline(x, lw, S.vf0);
+ }
function renderAll() {
const lw = (c) => Math.max(3, c.width / 150);
- const cs = $('cShot'), ci = $('cImg'), co = $('cOut'), cc = $('cCheck');
- if (S.shot) {
+ const cs = $('cShot'), ci = $('cImg'), co = $('cOut');
+ const ready = !!(S.shot && S.crop && S.vf);
+ sizeShot();
+ if (S.shot && ready) renderCheck(cs, lw(cs));
+ else if (S.shot) {
cs.width = S.shot.width; cs.height = S.shot.height; const x = cs.getContext('2d'); x.drawImage(S.shot, 0, 0);
- if (S.vf) outline(x, lw(cs));
+ if (S.vf0) outline(x, lw(cs), S.vf0);
}
if (S.img) {
ci.width = S.img.width; ci.height = S.img.height; const x = ci.getContext('2d'); x.drawImage(S.img, 0, 0);
const b = S.cands[S.sel] && S.cands[S.sel].b;
if (b && b.kind !== 'whole') {
- x.strokeStyle = getComputedStyle(document.documentElement).getPropertyValue('--guide').trim(); x.lineWidth = lw(ci);
+ x.strokeStyle = guide(); x.lineWidth = lw(ci);
if (b.pts) { x.beginPath(); b.pts.forEach(([px, py], i) => (i ? x.lineTo(px * ci.width, py * ci.height) : x.moveTo(px * ci.width, py * ci.height))); x.closePath(); x.stroke(); }
else if (b.corners) { x.beginPath(); b.corners.forEach(([px, py], i) => (i ? x.lineTo(px, py) : x.moveTo(px, py))); x.closePath(); x.stroke(); }
else x.strokeRect(b.x * ci.width, b.y * ci.height, b.w * ci.width, b.h * ci.height);
@@ -715,38 +1047,46 @@
if (drawPath && drawPath.length > 1) { x.setLineDash([lw(ci) * 3, lw(ci) * 2]); x.strokeStyle = '#ffb000'; x.lineWidth = lw(ci); x.beginPath(); drawPath.forEach(([px, py], i) => (i ? x.lineTo(px, py) : x.moveTo(px, py))); x.stroke(); x.setLineDash([]); }
if (drawBox) { x.setLineDash([lw(ci) * 3, lw(ci) * 2]); x.strokeStyle = '#ffb000'; x.lineWidth = lw(ci); if (S.mode === 'oval') { x.beginPath(); x.ellipse(drawBox.x + drawBox.w / 2, drawBox.y + drawBox.h / 2, drawBox.w / 2, drawBox.h / 2, 0, 0, 2 * Math.PI); x.stroke(); } else x.strokeRect(drawBox.x, drawBox.y, drawBox.w, drawBox.h); x.setLineDash([]); }
}
- if (S.shot && S.crop && S.vf) {
- renderOutput(co);
- cc.width = S.shot.width; cc.height = S.shot.height; const x = cc.getContext('2d');
- x.drawImage(S.shot, 0, 0); drawSubject(x, 0.85); outline(x, lw(cc));
- $('save').disabled = false;
- }
+ $('wellOut').classList.toggle('has', ready); $('save').disabled = !ready;
+ if (ready) { renderOutput(co); outline(co.getContext('2d'), lw(co), S.vf); }
+ $('outNote').textContent = (S.cal ? 'The file to inject. Green line = where the app reads the image' : 'The file to inject. Green line = the viewfinder') + (ready ? ` · ${outSize().join(' × ')} px` : '');
+ steps();
status();
}
+ let gridSaved = false, shotTaken = false, saved = false;
+ function steps() {
+ const plain = !!S.shot && !S.cal;
+ const done = [gridSaved || !!S.cal, shotTaken || !!S.cal, !!S.shot, !!S.img, saved];
+ const skipped = [plain && !gridSaved, plain, false, false, false];
+ let active = done.findIndex((d, i) => !d && !skipped[i]);
+ done.forEach((d, i) => { const el = $('step' + (i + 1)); el.classList.toggle('done', d && !skipped[i]); el.classList.toggle('skipped', skipped[i]); el.classList.toggle('active', i === active); });
+ $('wellShot').classList.toggle('next', active === 2); $('wellImg').classList.toggle('next', active === 3);
+ }
+ document.querySelectorAll('.step b').forEach((b) => {
+ const open = () => b.parentElement.classList.toggle('open');
+ b.addEventListener('click', open);
+ b.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(); } });
+ });
function status() {
- const el = $('status'); el.textContent = '';
- const pill = (t, cls) => { const s = document.createElement('span'); s.className = 'pill ' + (cls || ''); s.textContent = t; el.appendChild(s); };
- if (S.vf) {
- const r = S.vf.result, ok = r.confidence >= 0.6;
- pill(`viewfinder: ${r.mode} · ${r.shape} · confidence ${r.confidence.toFixed(2)}`, ok ? 'ok' : 'warn');
- if (!ok) pill('Low confidence: check the green line, or use the two-gradient method', 'warn');
- }
- if (S.subj) {
- const s = S.subj.sure;
- pill(`subject: ${S.subj.chosen ? nice(S.subj.chosen.kind) : 'none'} · confidence ${(s.confidence || 0).toFixed(2)}`, s.verdict === 'sure' ? 'ok' : 'warn');
- }
- if (S.vf && S.crop) {
- const inside = insideViewfinder();
- pill(inside ? 'subject inside the viewfinder' : 'subject goes outside the viewfinder', inside ? 'ok' : 'warn');
- pill(`output ${S.shot.width} × ${S.shot.height}`);
+ const list = (id) => { const el = $(id); el.textContent = ''; return (t, cls) => { const li = document.createElement('li'); if (cls) li.className = cls; li.textContent = t; el.appendChild(li); }; };
+ const shot = list('statusShot'), img = list('statusImg'), out = list('status');
+ if (S.vf0) {
+ if (S.cal) shot(`Calibrated: the app reads ${Math.round(S.cal.window_frac[1] * 100)}–${Math.round(S.cal.window_frac[3] * 100)}% of the image height`, 'ok');
+ else shot('Not calibrated: the image goes in the viewfinder on screen');
+ if (S.vf0.result.confidence < 0.6) shot('Viewfinder unsure: check the green line', 'warn');
}
+ if (S.subj && S.subj.sure.verdict !== 'sure') img('Subject unsure: draw a box around it', 'warn');
+ if (S.vf && S.crop) out(insideViewfinder() ? 'Subject is inside the green line' : 'Subject goes outside the green line: make it smaller or move it', insideViewfinder() ? 'ok' : 'warn');
+ if (note) out(note);
+ $('imgTools').setAttribute('aria-disabled', String(!S.img));
+ $('outTools').setAttribute('aria-disabled', String(!(S.vf && S.crop)));
}
// ---------- controls ----------
function syncControls() {
$('angleVal').textContent = `${(((angle() % 360) + 360) % 360).toFixed(1).replace(/\.0$/, '')}°`;
$('fine').value = S.fine; $('size').value = Math.round(S.size * 100);
- $('sizeVal').textContent = `${Math.round(S.size * 100)}% of largest fit`;
+ $('sizeVal').textContent = `${Math.round(S.size * 100)}%`;
}
const refit = () => { autoFit(); syncControls(); renderAll(); };
$('rotL').addEventListener('click', () => { S.rot90 = (S.rot90 + 3) % 4; refit(); });
@@ -763,16 +1103,16 @@
const toCanvasXY = (c, e) => { const r = c.getBoundingClientRect(); return [(e.clientX - r.left) * c.width / r.width, (e.clientY - r.top) * c.height / r.height]; };
- // move + resize on the check view
+ // move + resize on the output view
let drag = null;
- const cc = $('cCheck');
- cc.addEventListener('pointerdown', (e) => { if (!S.crop) return; const [x, y] = toCanvasXY(cc, e); drag = { x, y, cx: S.cx, cy: S.cy }; cc.setPointerCapture(e.pointerId); cc.classList.add('dragging'); });
+ const cc = $('cOut');
+ cc.addEventListener('pointerdown', (e) => { if (!S.crop || !S.vf) return; const [x, y] = toCanvasXY(cc, e); drag = { x, y, cx: S.cx, cy: S.cy }; cc.setPointerCapture(e.pointerId); cc.classList.add('dragging'); });
cc.addEventListener('pointermove', (e) => { if (!drag) return; const [x, y] = toCanvasXY(cc, e); S.cx = drag.cx + x - drag.x; S.cy = drag.cy + y - drag.y; requestAnimationFrame(renderAll); });
const endDrag = () => { drag = null; cc.classList.remove('dragging'); };
cc.addEventListener('pointerup', endDrag); cc.addEventListener('pointercancel', endDrag);
cc.addEventListener('wheel', (e) => { if (!S.crop) return; e.preventDefault(); S.size = Math.min(1.5, Math.max(0.1, S.size * (e.deltaY < 0 ? 1.04 : 1 / 1.04))); syncControls(); renderAll(); }, { passive: false });
- // move or resize the drawn subject on the image view
+ // move or resize the marked subject on the image view
const ci = $('cImg');
const selPts = (b) => b.pts || [[b.x, b.y], [b.x + b.w, b.y], [b.x + b.w, b.y + b.h], [b.x, b.y + b.h]];
const editable = () => { const b = S.cands[S.sel] && S.cands[S.sel].b; return b && (b.kind === 'manual' || b.kind === 'lasso') ? b : null; };
@@ -821,7 +1161,7 @@
clearTimeout(selTimer); selTimer = setTimeout(commitSel, 150);
}, { passive: false });
- // draw a subject box or free shape on the image view
+ // mark a subject box, oval or free shape on the image view
let drawBox = null, drawStart = null, drawPath = null;
const setMode = (m) => { S.mode = m; $('modeBox').setAttribute('aria-pressed', String(m === 'box')); $('modeOval').setAttribute('aria-pressed', String(m === 'oval')); $('modeFree').setAttribute('aria-pressed', String(m === 'free')); };
$('modeOval').addEventListener('click', () => setMode('oval'));
@@ -873,21 +1213,26 @@
$('save').addEventListener('click', async () => {
const c = document.createElement('canvas'); renderOutput(c);
const blob = await new Promise((r) => c.toBlob(r, 'image/png'));
- const base = (S.img && $('nameImg').textContent.replace(/^Example: /, '').replace(/\.[a-z0-9]+$/i, '').replace(/[^\w-]+/g, '_')) || 'image';
if (!blob) { setMsg('Save failed: could not create the PNG.'); return; }
- const filename = `padfit_${base}_${c.width}x${c.height}.png`;
- try {
- const url = URL.createObjectURL(blob);
- const a = document.createElement('a'); a.href = url; a.download = filename; a.style.display = 'none';
- document.body.appendChild(a); a.click(); a.remove();
- setTimeout(() => URL.revokeObjectURL(url), 10000);
- setMsg('Saved ' + filename);
- } catch (e) { setMsg('Save failed: ' + (e && e.message || e)); }
+ const base = (S.imgName || 'image').replace(/\.[a-z0-9]+$/i, '').replace(/[^\w-]+/g, '_');
+ const filename = `padded_${base}_${c.width}x${c.height}.png`;
+ try { await saveBlob(blob, filename); saved = true; steps(); setMsg('Saved ' + filename); }
+ catch (e) { setMsg(e && e.code === 'declined' ? '' : 'Save failed: ' + (e && e.message || e)); }
});
+ // The screenshot panel takes the phone's shape: its width follows its height.
+ function sizeShot() {
+ const w = $('wellShot');
+ if (innerWidth <= 1100) { w.style.width = ''; return; }
+ const ar = S.shot ? S.shot.width / S.shot.height : 9 / 19.5;
+ w.style.width = Math.round(Math.min(360, Math.max(150, w.clientHeight * ar))) + 'px';
+ }
+ addEventListener('resize', sizeShot);
+
syncControls();
+ sizeShot();
boot();
})();
-
\ No newline at end of file
+