From 3ca64ad7eb47252c5dea49ca6d481fa16d3a6c75 Mon Sep 17 00:00:00 2001 From: evlist Date: Fri, 21 Apr 2023 21:28:09 +0200 Subject: [PATCH] Avoiding raising errors when there is no elevation in exif data --- src/components/import/ImportSingleFile.tsx | 7 +++++++ src/lib/exif.ts | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/import/ImportSingleFile.tsx b/src/components/import/ImportSingleFile.tsx index e75bac5..42acb41 100644 --- a/src/components/import/ImportSingleFile.tsx +++ b/src/components/import/ImportSingleFile.tsx @@ -108,6 +108,13 @@ const ImportSingleFile: Component = ({ file: file }) => { async () => { const imageUrl = reader.result; const exifObj = piexif.load(imageUrl); + console.log({ + caller: 'ImportSingleFile / Jpeg', + file, + type: file.type, + result: reader.result, + exifObj, + }); const id = exifObj.Exif[piexif.ExifIFD.ImageUniqueID]; const gps = getGps(exifObj); const date = getDate(exifObj); diff --git a/src/lib/exif.ts b/src/lib/exif.ts index 50e0519..a1b7469 100644 --- a/src/lib/exif.ts +++ b/src/lib/exif.ts @@ -21,6 +21,8 @@ export const getGps = (exifObj: any) => { return { latitude: toNumber(1), longitude: toNumber(3), - elevation: exifObj.GPS[6][0] / exifObj.GPS[6][1], + elevation: exifObj.GPS[6] + ? exifObj.GPS[6][0] / exifObj.GPS[6][1] + : undefined, }; };