Chỉnh sửa phần upload ảnh
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
const fs = require('fs');
|
||||
const exifr = require('exifr');
|
||||
const { exiftool } = require('exiftool-vendored');
|
||||
const piexif = require('piexifjs');
|
||||
|
||||
/**
|
||||
* Parses GPS coordinates from an image file using exifr
|
||||
* Parses GPS coordinates from an image file (JPEG or DNG) using ExifTool
|
||||
* @param {string} filePath - Path to the image file
|
||||
* @returns {Promise<{lat: number, lng: number}|null>} GPS coordinates or null if not found
|
||||
*/
|
||||
const getGPSCoordinates = async (filePath) => {
|
||||
try {
|
||||
const gps = await exifr.gps(filePath);
|
||||
if (gps && typeof gps.latitude === 'number' && typeof gps.longitude === 'number') {
|
||||
const tags = await exiftool.read(filePath);
|
||||
if (tags && typeof tags.GPSLatitude === 'number' && typeof tags.GPSLongitude === 'number') {
|
||||
return {
|
||||
lat: gps.latitude,
|
||||
lng: gps.longitude
|
||||
lat: tags.GPSLatitude,
|
||||
lng: tags.GPSLongitude
|
||||
};
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.warn(`Could not read EXIF GPS from ${filePath}: ${error.message}`);
|
||||
console.warn(`ExifTool could not read GPS from ${filePath}: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user