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;
}
};
+5 -2
View File
@@ -7,10 +7,13 @@ const sharp = require('sharp');
*/
const resizeTo8K = async (inputPath, outputPath) => {
try {
await sharp(inputPath)
// Sử dụng failOn: 'none' để Sharp không dừng lại khi gặp lỗi metadata nhỏ trong tệp RAW/DNG.
// Khi libvips trên server hỗ trợ libraw, Sharp sẽ tự động render dữ liệu DNG này.
await sharp(inputPath, { failOn: 'none' })
.removeAlpha() // Loại bỏ các kênh phụ/alpha thường gây lỗi 'multiband' trên tệp DNG
.rotate() // Tự động xoay ảnh dựa trên EXIF orientation
.resize(8192, 4096, {
fit: 'fill' // Ensures the output is exactly 8192x4096
fit: 'cover' // Thay đổi thành 'cover' để giữ tỷ lệ 2:1 mà không làm méo ảnh
})
.jpeg({
quality: 85,