Chỉnh sửa phần upload ảnh

This commit is contained in:
2026-06-09 11:06:25 +07:00
parent 913867720f
commit 2fba77d50c
10 changed files with 171 additions and 27 deletions
+7 -7
View File
@@ -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;
}
};