-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): image size and xywh when converting attachment to image
- Loading branch information
Showing
6 changed files
with
77 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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); | ||
}; | ||
|
||
img.src = URL.createObjectURL(file); | ||
Check warning Code scanning / CodeQL DOM text reinterpreted as HTML Medium DOM text Error loading related location Loading DOM text Error loading related location Loading |
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters