Compress over-limit images client-side to fit instead of rejecting them

Previously an image at/over the upload size limit was simply rejected with
"File too large", and the limit was hardcoded to 50 MB in the client even when
the server was configured lower. Now:

- The configured image limit (upload.max_size_mb) is surfaced to the client via
  pageData.UploadMaxMB and passed to GlimmerUpload.init({maxImageMB}).
- Selecting an over-limit image prompts to compress it in the browser to fit;
  the oversized original is never uploaded (Cancel aborts). Images over 10 MB
  but under the limit get an optional "compress for faster upload" prompt.
- compressToTarget iteratively fits the file just under the limit: it tries a
  JPEG quality ladder (0.85 → 0.4) at each resolution and halves the resolution
  on failure, down to a 320 px floor, targeting 95% of the limit for headroom.
  If it can't get under the limit it reports the smallest size achieved and
  uploads nothing.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
lucioandClaude Opus 4.8 committed 2026-06-04 23:24:11 -07:00
1 parent 1be1e0c001
commit f013e1f22b
4 files changed
+129 -50

No files matched your search

@@ -183,6 +183,7 @@
imgInput: document.getElementById('img-input'),
fileInput: document.getElementById('file-input'),
statusEl: document.getElementById('upload-status'),
maxImageMB: {{.UploadMaxMB}},
onUploaded: function() { location.reload(); }
});
</script>