fix: prefer dynamic import for image-size
(#6495)
This commit is contained in:
parent
abaf860af7
commit
09813f1610
1 changed files with 5 additions and 2 deletions
|
@ -1,4 +1,3 @@
|
|||
import sizeOf from 'image-size';
|
||||
import fs from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { ImageMetadata, InputFormat } from '../types.js';
|
||||
|
@ -7,10 +6,14 @@ export interface Metadata extends ImageMetadata {
|
|||
orientation?: number;
|
||||
}
|
||||
|
||||
let sizeOf: typeof import('image-size').default | undefined;
|
||||
export async function imageMetadata(
|
||||
src: URL | string,
|
||||
data?: Buffer
|
||||
): Promise<Metadata | undefined> {
|
||||
if (!sizeOf) {
|
||||
sizeOf = await import('image-size').then(mod => mod.default);
|
||||
}
|
||||
let file = data;
|
||||
if (!file) {
|
||||
try {
|
||||
|
@ -20,7 +23,7 @@ export async function imageMetadata(
|
|||
}
|
||||
}
|
||||
|
||||
const { width, height, type, orientation } = await sizeOf(file);
|
||||
const { width, height, type, orientation } = await sizeOf!(file);
|
||||
const isPortrait = (orientation || 0) >= 5;
|
||||
|
||||
if (!width || !height || !type) {
|
||||
|
|
Loading…
Reference in a new issue