0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-13 22:11:20 -05:00
astro/packages/integrations/image/src/metadata.ts
Fred K. Bot 94143fcdba
[ci] release (#3789)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-07-01 17:43:26 +00:00

20 lines
425 B
TypeScript

import fs from 'fs/promises';
import sizeOf from 'image-size';
import { ImageMetadata, InputFormat } from './types';
export async function metadata(src: string): Promise<ImageMetadata | undefined> {
const file = await fs.readFile(src);
const { width, height, type } = await sizeOf(file);
if (!width || !height || !type) {
return undefined;
}
return {
src,
width,
height,
format: type as InputFormat,
};
}