@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/main.nodejs.js +1 -1
- package/dist/main.nodejs.js.map +1 -1
- package/dist/plugin.zip +0 -0
- package/package.json +1 -1
- package/src/ui/editor-html.ts +14 -5
package/dist/plugin.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/ui/editor-html.ts
CHANGED
|
@@ -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 =
|
|
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
|
-
//
|
|
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
|
|
1013
|
-
|
|
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
|
}
|