Updated the EXIF ​​service to simplify EXIF ​​data handling.

master
Alix JEUDI--LEMOINE 24 hours ago
parent 9515db02bf
commit 261c7033a1

@ -5,35 +5,10 @@ import * as exifr from 'exifr';
providedIn: 'root', providedIn: 'root',
}) })
export class ExifService { export class ExifService {
private getExifData(file: File): Promise<any> {
return exifr.parse(file);
}
async getAllExifData(file: File): Promise<any> {
try {
return await this.getExifData(file);
} catch (error) {
console.error('Error reading EXIF data:', error);
return;
}
}
async getOrientation(file: File): Promise<number | undefined> { async getOrientation(file: File): Promise<number | undefined> {
try { try {
const exifData = await this.getExifData(file); return await exifr.orientation(file);
return exifData.Orientation;
} catch (error) { } catch (error) {
console.error('Error reading EXIF data:', error);
return undefined;
}
}
async getDeviceModel(file: File): Promise<string | undefined> {
try {
const exifData = await this.getExifData(file);
return exifData.Model;
} catch (error) {
console.error('Error reading EXIF data:', error);
return undefined; return undefined;
} }
} }
@ -42,37 +17,18 @@ export class ExifService {
file: File file: File
): Promise<{ latitude?: number; longitude?: number }> { ): Promise<{ latitude?: number; longitude?: number }> {
try { try {
const exifData = await this.getExifData(file); return exifr.gps(file);
return {
latitude: exifData.GPSLatitude
? this.convertToDecimal(exifData.GPSLatitude, exifData.GPSLatitudeRef)
: undefined,
longitude: exifData.GPSLongitude
? this.convertToDecimal(
exifData.GPSLongitude,
exifData.GPSLongitudeRef
)
: undefined,
};
} catch (error) { } catch (error) {
console.error('Error reading EXIF data:', error);
return {}; return {};
} }
} }
async getDateTime(file: File): Promise<string | boolean> { async getDateTime(file: File): Promise<string> {
try { try {
const exifData = await this.getExifData(file); const data = await exifr.parse(file);
return exifData.DateTime; return data.DateTimeOriginal.toISOString();
} catch (error) { } catch (error) {
console.error('Error reading EXIF data:', error); return '';
return false;
} }
} }
private convertToDecimal(coordinate: number[], direction: string): number {
if (!coordinate || coordinate.length !== 3) return NaN;
const decimal = coordinate[0] + coordinate[1] / 60 + coordinate[2] / 3600;
return direction === 'S' || direction === 'W' ? -decimal : decimal;
}
} }

Loading…
Cancel
Save