diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/adjust.html | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tools/adjust.html b/tools/adjust.html index 429bffc..f0d768f 100644 --- a/tools/adjust.html +++ b/tools/adjust.html @@ -36,6 +36,7 @@ <textarea id="cmd" readonly></textarea><br> <button id="copy">Copy ImageMagick Commands</button> +<button id="dlScript">Download bash script</button> <script> const canvas = document.getElementById('cv'); @@ -257,18 +258,41 @@ document.getElementById('dl').onclick = () => { s(out1, "clipped_" + name1); s(out2, "clipped_" + name2); }; -function updateCmd() { - if (!l1 || !l2) return; +const SOURCE_FILES = ['albedo.png','depth.png','matid.png','normal.png','shadow.png','source.png','transp.png']; + +function buildCommands() { + if (!l1 || !l2) return null; let x0 = Math.max(0, ox), y0 = Math.max(0, oy); let w = Math.floor(Math.min(canvas.width, ox + i2.width * sx) - x0); let h = Math.floor(Math.min(canvas.height, oy + i2.height * sy) - y0); - if (w <= 0 || h <= 0) return; + if (w <= 0 || h <= 0) return null; let cr = `${w}x${h}+${Math.round(x0)}+${Math.round(y0)}`; - cmdEl.value = `magick "${name1}" -crop ${cr} +repage "clipped_${name1}"\n` + - `magick "${name2}" -virtual-pixel black -distort AffineProjection "${sx.toFixed(6)},0,0,${sy.toFixed(6)},${ox.toFixed(2)},${oy.toFixed(2)}" -crop ${cr} +repage "clipped_${name2}"`; + // One crop command per source file + let lines = SOURCE_FILES.map(f => + `magick "${f}" -crop ${cr} +repage "clipped/${f}"` + ); + // Target: distort + crop, output to clipped/<name2> (no prefix mangling) + lines.push(`magick "${name2}" -virtual-pixel black -distort AffineProjection "${sx.toFixed(6)},0,0,${sy.toFixed(6)},${ox.toFixed(2)},${oy.toFixed(2)}" -crop ${cr} +repage "clipped/${name2}"`); + return lines; +} + +function updateCmd() { + let lines = buildCommands(); + if (!lines) return; + cmdEl.value = lines.join('\n'); } document.getElementById('copy').onclick = () => { cmdEl.select(); navigator.clipboard.writeText(cmdEl.value); }; + +document.getElementById('dlScript').onclick = () => { + let lines = buildCommands(); + if (!lines) return alert("Set up images first."); + let script = '#!/bin/bash\nmkdir -p clipped\n\n' + lines.join('\n') + '\n'; + let a = document.createElement('a'); + a.download = 'align.sh'; + a.href = URL.createObjectURL(new Blob([script], { type: 'text/x-sh' })); + a.click(); +}; iterSlider.oninput = () => document.getElementById('iterVal').textContent = iterSlider.value; </script> </body> |
