fix(editor): image size and xywh when converting attachment to image (#10200)

In Edgeless, the image size should be read when converting attachment to image:

* fix `size`
* fix `xywh`
This commit is contained in:
fundon
2025-02-20 05:16:21 +00:00
parent ff0ce1a962
commit adc003862b
10 changed files with 87 additions and 41 deletions

View File

@@ -0,0 +1,28 @@
import DOMPurify from 'dompurify';
export function readImageSize(file: File | Blob) {
return new Promise<{ width: number; height: number }>(resolve => {
const size = { width: 0, height: 0 };
if (!file.type.startsWith('image/')) {
resolve(size);
return;
}
const img = new Image();
img.onload = () => {
size.width = img.width;
size.height = img.height;
URL.revokeObjectURL(img.src);
resolve(size);
};
img.onerror = () => {
URL.revokeObjectURL(img.src);
resolve(size);
};
const sanitizedURL = DOMPurify.sanitize(URL.createObjectURL(file));
img.src = sanitizedURL;
});
}

View File

@@ -8,6 +8,7 @@ export * from './edgeless';
export * from './event';
export * from './file';
export * from './fractional-indexing';
export * from './image';
export * from './insert';
export * from './is-abort-error';
export * from './math';