MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / fetchImageDimensions

Function fetchImageDimensions

packages/utilities/src/files.ts:25–49  ·  view source on GitHub ↗
(
  file: File
)

Source from the content-addressed store, hash-verified

23}
24
25export async function fetchImageDimensions(
26 file: File
27): Promise<{ width: number; height: number }> {
28 return new Promise((resolve, reject) => {
29 var url = URL.createObjectURL(file);
30 var image = new Image();
31
32 image.onload = function () {
33 if (!image.width || !image.height) {
34 return reject(new Error(`Image is empty ${file.name}`));
35 }
36 resolve({
37 width: image.width,
38 height: image.height,
39 });
40 URL.revokeObjectURL(image.src);
41 };
42
43 image.onerror = function () {
44 reject(new Error(`Couldn't load the image ${file.name}`));
45 };
46
47 image.src = url;
48 });
49}
50
51interface Dimensions {
52 width: number;

Callers 1

getFormDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected