UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

27 lines • 1.55 kB
/** * Measures an image's intrinsic size without keeping its pixels. * * Floorplan needs one number from a logo's pixels: the aspect ratio, to fit the logo inside a * booth. `createImageBitmap` gives that number at low cost. The browser decodes the image on its * own thread. Then it resolves a promise. The main thread pays only for the call and for the * promise resolution, not for the decode itself. This is the difference between * `createImageBitmap` and an `<img>` element, which decodes on the same thread as the page. * * The function closes the bitmap right after it reads the size. A caller can start as many calls * as it wants. At any instant, only a few bitmaps exist in memory: the ones the browser's decoder * already finished but did not yet hand back. The whole batch of logos never sits in memory * together. One cost remains, and this cost is accepted: each logo gets decoded twice, once here * and once in the atlas worker. This happens because a Blob cannot report its own size, and the * renderer does not report one back either. * * This function has no `<img>` fallback. `createImageBitmap` works on every build target that * this SDK supports. The only targets that lack `createImageBitmap` are targets where the whole * SDK already fails to run. * @param blob - The image bytes. * @returns The size, or `null` if the bytes cannot be decoded. */ export declare function blobImageSize(blob: Blob): Promise<{ width: number; height: number; } | null>; //# sourceMappingURL=blob-image-size.d.ts.map