exif(): read HEIF/HEIC originals with exifreader (closes #145)
check / check (push) Successful in 2m10s
check / check (push) Successful in 2m10s
`photo.exif()` and `quak backup-metadata --exif` now read EXIF through `exifreader`. HEIC/HEIF originals get EXIF, including a live photo's image, as do the other formats `exifreader` reads. It replaces `exif-reader` and the hand-written JPEG scan. `PhotoExif` is unchanged. The `backup-metadata` dump now holds `exifreader`'s tag output, with unnamed tags keyed `undefined-` plus their number. GPS altitude without a reference counts as above sea level. A latitude or longitude without its hemisphere tag, an unreadable text tag, and a date the parser rejects each give no field. Licence: `exifreader` is MPL-2.0, used unmodified. Model: opus-5-5
This commit was merged in pull request #147.
This commit is contained in:
+16
-14
@@ -1,9 +1,8 @@
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import * as jpeg from "jpeg-js";
|
||||
import exifReader from "exif-reader";
|
||||
import type { Client } from "./client.js";
|
||||
import { extractExifFromJpeg } from "./exif.js";
|
||||
import { readExifTags } from "./exif.js";
|
||||
import type { Library, Photo } from "./library/index.js";
|
||||
import { sanitizeFileName } from "./filename.js";
|
||||
import {
|
||||
@@ -20,9 +19,10 @@ export interface MetadataBackupOptions {
|
||||
onProgress?: ProgressCallback;
|
||||
}
|
||||
|
||||
// Extract dimensions, EXIF and XMP from a file's bytes. When the EXIF segment
|
||||
// is malformed or cannot be parsed, the record carries the reason in
|
||||
// `exifError`.
|
||||
// Extract dimensions, EXIF and XMP from a file's bytes. `exif` is the EXIF tags
|
||||
// exifreader returns, from any image format it reads. When it finds an EXIF
|
||||
// block but reads no tag from it, the record keeps the block's bytes, base64,
|
||||
// in `exifRaw`, with the reason in `exifError`.
|
||||
export const extractImageMetadata = (
|
||||
fileBytes: Uint8Array,
|
||||
): Record<string, unknown> | undefined => {
|
||||
@@ -39,19 +39,21 @@ export const extractImageMetadata = (
|
||||
result.height = decoded.height;
|
||||
} catch {
|
||||
// Not every original is a JPEG (PNG, HEIC, video), so a failed decode
|
||||
// is expected and only means no dimensions; a malformed JPEG is still
|
||||
// is expected and only means no dimensions; unreadable EXIF is still
|
||||
// reported below through `exifError`.
|
||||
}
|
||||
|
||||
const { exif, error } = extractExifFromJpeg(fileBytes);
|
||||
if (error) result.exifError = error;
|
||||
if (exif) {
|
||||
try {
|
||||
result.exif = exifReader(exif);
|
||||
} catch (err) {
|
||||
result.exifRaw = exif.toString("base64");
|
||||
result.exifError = err instanceof Error ? err.message : String(err);
|
||||
const tags = readExifTags(fileBytes);
|
||||
if (tags?.exif && Object.keys(tags.exif).length > 0) {
|
||||
result.exif = tags.exif;
|
||||
} else if (tags?.exif) {
|
||||
const block = tags.metadataRange?.blocks.find((b) => b.type === "exif");
|
||||
if (block) {
|
||||
result.exifRaw = Buffer.from(
|
||||
fileBytes.subarray(block.start, block.end),
|
||||
).toString("base64");
|
||||
}
|
||||
result.exifError = "no tag could be read from the EXIF block";
|
||||
}
|
||||
|
||||
// Extract XMP (look for "http://ns.adobe.com/xap" in the bytes)
|
||||
|
||||
Reference in New Issue
Block a user