fix: photo edit by admin
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import exifr from 'exifr';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const searchDir = '.';
|
||||
|
||||
async function walk(dir) {
|
||||
let files = [];
|
||||
const list = fs.readdirSync(dir);
|
||||
for (const file of list) {
|
||||
if (file === 'node_modules' || file === '.git' || file === '.vscode') continue;
|
||||
const fullPath = path.join(dir, file);
|
||||
const stat = fs.statSync(fullPath);
|
||||
if (stat.isDirectory()) {
|
||||
files = files.concat(await walk(fullPath));
|
||||
} else {
|
||||
if (['.jpg', '.jpeg', '.png'].includes(path.extname(file).toLowerCase())) {
|
||||
files.push(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const images = await walk(searchDir);
|
||||
console.log(`Found ${images.length} images to scan...`);
|
||||
for (const img of images) {
|
||||
try {
|
||||
const gps = await exifr.gps(img);
|
||||
if (gps) {
|
||||
console.log(`FOUND IMAGE WITH GPS: ${img}`, gps);
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
console.log('Scan completed.');
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,39 @@
|
||||
import EXIF from 'exif-js';
|
||||
import exifr from 'exifr';
|
||||
import fs from 'fs';
|
||||
|
||||
async function test() {
|
||||
const files = [
|
||||
'./node_modules/exif-js/example/dsc_09827.jpg',
|
||||
'./node_modules/exif-js/example/DSCN0614_small.jpg',
|
||||
'./node_modules/exif-js/example/Bloated-Hero.jpg',
|
||||
'./node_modules/exif-js/example/Bush-dog.jpg'
|
||||
];
|
||||
|
||||
for (const f of files) {
|
||||
console.log(`--- Testing file: ${f} ---`);
|
||||
try {
|
||||
const gpsExifr = await exifr.gps(f);
|
||||
console.log(' exifr.gps:', gpsExifr);
|
||||
} catch (e) {
|
||||
console.log(' exifr error:', e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
const data = fs.readFileSync(f);
|
||||
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
||||
const parsed = await exifr.parse(arrayBuffer);
|
||||
console.log(' exifr.parse output:', parsed ? {
|
||||
latitude: parsed.latitude,
|
||||
longitude: parsed.longitude,
|
||||
DateTimeOriginal: parsed.DateTimeOriginal,
|
||||
CreateDate: parsed.CreateDate,
|
||||
ModifyDate: parsed.ModifyDate
|
||||
} : 'null');
|
||||
} catch (e) {
|
||||
console.log(' exifr.parse error:', e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
||||
Reference in New Issue
Block a user