feat: add exif data to image tags
Some checks failed
Deploy to SFTP Server / build (push) Failing after 1m34s
Some checks failed
Deploy to SFTP Server / build (push) Failing after 1m34s
This commit is contained in:
@ -1,16 +1,14 @@
|
||||
let loadingSharp = false;
|
||||
import { rgbaToThumbHash } from "thumbhash";
|
||||
import ExifReader from 'exifreader';
|
||||
|
||||
let s: typeof import("sharp") | undefined;
|
||||
|
||||
async function getSharp(): Promise<typeof import("sharp") | undefined> {
|
||||
|
||||
if (s) return s;
|
||||
|
||||
if (import.meta.env.MODE !== "development") {
|
||||
s = (await import("sharp")).default;
|
||||
return s;
|
||||
}
|
||||
s = (await import("sharp")).default;
|
||||
return s;
|
||||
|
||||
if (!loadingSharp) {
|
||||
loadingSharp = true;
|
||||
@ -42,3 +40,33 @@ export async function generateThumbHash(image: { width: number, height: number }
|
||||
const buffer = rgbaToThumbHash(smallWidth, smallHeight, smallImg);
|
||||
return Buffer.from(buffer).toString("base64");
|
||||
}
|
||||
|
||||
const allowedExif = [
|
||||
"ApertureValue",
|
||||
"DateTimeOriginal",
|
||||
"ExposureTime",
|
||||
"ApertureValue",
|
||||
"FNumber",
|
||||
"FocalLength",
|
||||
"GPSLatitude",
|
||||
"GPSLongitude",
|
||||
"GPSAltitude",
|
||||
"IsoSpeedRatings",
|
||||
];
|
||||
|
||||
export async function getExifData(image: { fsPath: string }) {
|
||||
const sharp = await getSharp();
|
||||
if (!sharp) return;
|
||||
const tags = await ExifReader.load(image.fsPath, { async: true });
|
||||
|
||||
const out: Record<string, any> = {};
|
||||
let hasExif = false;
|
||||
|
||||
for (const key of allowedExif) {
|
||||
if (!tags[key]) continue;
|
||||
hasExif = true;
|
||||
out[key] = tags[key].description;
|
||||
}
|
||||
|
||||
return hasExif ? out : undefined;
|
||||
}
|
||||
|
Reference in New Issue
Block a user