- Removed unused imports and functions from canvas.tsx to streamline the codebase. - Introduced several helper modules for improved organization and maintainability, including canvas-helpers, canvas-node-change-helpers, and canvas-media-utils. - Updated documentation in CLAUDE.md to reflect changes in the canvas architecture and the purpose of new internal modules.
29 lines
704 B
TypeScript
29 lines
704 B
TypeScript
export async function getImageDimensions(
|
|
file: File,
|
|
): Promise<{ width: number; height: number }> {
|
|
return new Promise((resolve, reject) => {
|
|
const objectUrl = URL.createObjectURL(file);
|
|
const image = new window.Image();
|
|
|
|
image.onload = () => {
|
|
const width = image.naturalWidth;
|
|
const height = image.naturalHeight;
|
|
URL.revokeObjectURL(objectUrl);
|
|
|
|
if (!width || !height) {
|
|
reject(new Error("Could not read image dimensions"));
|
|
return;
|
|
}
|
|
|
|
resolve({ width, height });
|
|
};
|
|
|
|
image.onerror = () => {
|
|
URL.revokeObjectURL(objectUrl);
|
|
reject(new Error("Could not decode image"));
|
|
};
|
|
|
|
image.src = objectUrl;
|
|
});
|
|
}
|