-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathread-image-metadata.ts
More file actions
28 lines (25 loc) · 696 Bytes
/
read-image-metadata.ts
File metadata and controls
28 lines (25 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import exifr from 'exifr'
import type { ImageMetadataFormatted } from '../../types'
import { formatImageMetadata } from './format'
export async function readImageMetadata(
filePath: string
): Promise<ImageMetadataFormatted | undefined> {
if (!filePath) return undefined
try {
const exifRaw = await exifr.parse(filePath, {
exif: true,
iptc: true,
xmp: true,
icc: false,
gps: true,
mergeOutput: false
})
if (!exifRaw) return undefined
return formatImageMetadata(exifRaw)
} catch (error) {
console.error(
`Failed to extract metadata: ${error instanceof Error ? error.message : String(error)}`
)
return undefined
}
}