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

Function getImageDimensionsFromUrl

packages/utilities/src/files.ts:56–80  ·  view source on GitHub ↗
(filename: string)

Source from the content-addressed store, hash-verified

54}
55
56export function getImageDimensionsFromUrl(filename: string): Dimensions | null {
57 const extension = getExtension(filename) as string;
58 const underscore = filename.lastIndexOf('_');
59 const x = filename.lastIndexOf('x');
60 if (underscore === -1 || x === -1) {
61 return null;
62 }
63 if (x < underscore) {
64 return null;
65 }
66 const part = filename.substring(
67 underscore + 1,
68 filename.length - extension.length - 1
69 );
70 const [part1, part2] = part.split('x');
71
72 const width = Number(part1);
73 const height = Number(part2);
74
75 if (width && height) {
76 return { width, height };
77 }
78
79 return null;
80}
81
82export async function getFormData(files: File[]) {
83 const data = new FormData();

Callers 2

files.test.tsFile · 0.90
getWidthHeightFunction · 0.90

Calls 1

getExtensionFunction · 0.85

Tested by

no test coverage detected