mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-03 16:16:59 +00:00
fix: give a photo's date only from when it was taken, not when the file changed
exif.test.ts: the case "falls back to the file date" now expects no date, since IFD0's DateTime is the file's change date, not the date the photo was taken.
This commit is contained in:
@@ -72,9 +72,9 @@ describe('readPhotoExif', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('falls back to the file date when the original date is missing', () => {
|
||||
it('gives no date when only the date the file changed is there', () => {
|
||||
const bytes = jpeg(tiff(false, { ifd0: [{ tag: 0x0132, type: 2, ascii: '2026:11:01 09:00:00' }], exif: [], gps: [] }));
|
||||
expect(readPhotoExif(bytes)).toEqual({ taken: '2026-11-01T09:00:00' });
|
||||
expect(readPhotoExif(bytes)).toEqual({});
|
||||
});
|
||||
|
||||
it('gives nothing for a JPEG without EXIF, a PNG or broken bytes', () => {
|
||||
|
||||
+2
-3
@@ -12,7 +12,6 @@ export interface PhotoExif {
|
||||
|
||||
const TAG_EXIF_IFD = 0x8769;
|
||||
const TAG_GPS_IFD = 0x8825;
|
||||
const TAG_DATETIME = 0x0132;
|
||||
const TAG_DATETIME_ORIGINAL = 0x9003;
|
||||
const TAG_OFFSET_TIME_ORIGINAL = 0x9011;
|
||||
const GPS_LAT_REF = 1;
|
||||
@@ -126,8 +125,8 @@ export function readPhotoExif(data: ArrayBuffer | Uint8Array): PhotoExif {
|
||||
const ifd0 = tiff.ifd(tiff.firstIfd());
|
||||
const exifAt = tiff.long(ifd0.get(TAG_EXIF_IFD));
|
||||
const exif = exifAt ? tiff.ifd(exifAt) : new Map<number, Entry>();
|
||||
const taken = exifDate(tiff.ascii(exif.get(TAG_DATETIME_ORIGINAL)), tiff.ascii(exif.get(TAG_OFFSET_TIME_ORIGINAL)))
|
||||
?? exifDate(tiff.ascii(ifd0.get(TAG_DATETIME)), undefined);
|
||||
// Only the date the photo was taken: IFD0's DateTime is when the file was last changed.
|
||||
const taken = exifDate(tiff.ascii(exif.get(TAG_DATETIME_ORIGINAL)), tiff.ascii(exif.get(TAG_OFFSET_TIME_ORIGINAL)));
|
||||
if (taken) out.taken = taken;
|
||||
const gpsAt = tiff.long(ifd0.get(TAG_GPS_IFD));
|
||||
if (gpsAt) {
|
||||
|
||||
Reference in New Issue
Block a user