mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: show real image dimensions in right pane for DNG/RAW files
The preview endpoint now returns X-Original-Width/Height headers with dimensions read from Sharp metadata (or ExifTool for RAW files). The frontend stores these in FileEntry and the ImageViewer prefers them over the browser's naturalWidth/naturalHeight, which reflects the resized preview rather than the original sensor dimensions.
This commit is contained in:
@@ -135,6 +135,34 @@ export async function writeMetadata(
|
||||
}
|
||||
}
|
||||
|
||||
export async function readImageDimensions(
|
||||
buffer: Buffer,
|
||||
ext?: string,
|
||||
): Promise<{ width: number; height: number } | null> {
|
||||
try {
|
||||
const bin = await findExiftool();
|
||||
const suffix = ext ? `.${ext.replace(/^\./, "")}` : ".jpg";
|
||||
const id = randomUUID();
|
||||
const tempPath = join(tmpdir(), `exif-dim-${id}${suffix}`);
|
||||
|
||||
try {
|
||||
await writeFile(tempPath, buffer);
|
||||
const { stdout } = await execFileAsync(
|
||||
bin,
|
||||
["-json", "-ImageWidth", "-ImageHeight", tempPath],
|
||||
{ timeout: 10_000 },
|
||||
);
|
||||
const [data] = JSON.parse(stdout);
|
||||
if (!data?.ImageWidth || !data?.ImageHeight) return null;
|
||||
return { width: data.ImageWidth, height: data.ImageHeight };
|
||||
} finally {
|
||||
await rm(tempPath, { force: true }).catch(() => {});
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Settings shape that buildTagArgs accepts */
|
||||
export interface EditMetadataSettings {
|
||||
title?: string;
|
||||
|
||||
Reference in New Issue
Block a user