@blueharford/scrypted-spatial-awareness 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueharford/scrypted-spatial-awareness",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Cross-camera object tracking for Scrypted NVR with spatial awareness",
5
5
  "author": "Joshua Seidel <blueharford>",
6
6
  "license": "Apache-2.0",
@@ -986,14 +986,14 @@ export const EDITOR_HTML = `<!DOCTYPE html>
986
986
 
987
987
  function uploadFloorPlan() { document.getElementById('upload-modal').classList.add('active'); }
988
988
 
989
- // Compress and resize image to avoid 413 errors
990
- function compressImage(img, maxSize = 1600, quality = 0.8) {
989
+ // Compress and resize image to avoid 413 errors (Scrypted has ~50KB limit)
990
+ function compressImage(img, maxSize = 800, quality = 0.5) {
991
991
  return new Promise((resolve) => {
992
992
  const canvas = document.createElement('canvas');
993
993
  let width = img.width;
994
994
  let height = img.height;
995
995
 
996
- // Resize if larger than maxSize
996
+ // Always resize to fit within maxSize
997
997
  if (width > maxSize || height > maxSize) {
998
998
  if (width > height) {
999
999
  height = Math.round(height * maxSize / width);
@@ -1009,9 +1009,18 @@ export const EDITOR_HTML = `<!DOCTYPE html>
1009
1009
  const ctx = canvas.getContext('2d');
1010
1010
  ctx.drawImage(img, 0, 0, width, height);
1011
1011
 
1012
- // Convert to JPEG for better compression
1013
- const compressed = canvas.toDataURL('image/jpeg', quality);
1012
+ // Convert to JPEG with aggressive compression
1013
+ let compressed = canvas.toDataURL('image/jpeg', quality);
1014
1014
  console.log('Compressed image from', img.width, 'x', img.height, 'to', width, 'x', height, 'size:', Math.round(compressed.length / 1024), 'KB');
1015
+
1016
+ // If still too large, compress more
1017
+ let q = quality;
1018
+ while (compressed.length > 50000 && q > 0.1) {
1019
+ q -= 0.1;
1020
+ compressed = canvas.toDataURL('image/jpeg', q);
1021
+ console.log('Re-compressed at quality', q.toFixed(1), 'size:', Math.round(compressed.length / 1024), 'KB');
1022
+ }
1023
+
1015
1024
  resolve(compressed);
1016
1025
  });
1017
1026
  }