Switch to Sharp for EXIF removal
This commit is contained in:
parent
f74ef19180
commit
45689acb26
@ -133,3 +133,15 @@ export const blurImageFromUrl = async (url: string) =>
|
||||
fetch(decodeURIComponent(url))
|
||||
.then(res => res.arrayBuffer())
|
||||
.then(buffer => blurImage(buffer));
|
||||
|
||||
export const removeGpsData = async (image: ArrayBuffer) =>
|
||||
generateBase64(image, sharp => sharp
|
||||
.withExifMerge({
|
||||
IFD3: {
|
||||
GPSLatitudeRef: '',
|
||||
GPSLatitude: '',
|
||||
GPSLongitudeRef: '',
|
||||
GPSLongitude: '',
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
@ -18,7 +18,7 @@ export const convertUploadToPhoto = async (
|
||||
console.log('Fetching original file');
|
||||
const fileBytes = await fetch(urlOrigin, { cache: 'no-store' })
|
||||
.then(res => res.arrayBuffer());
|
||||
const fileWithoutGps = stripGpsFromFile(fileBytes);
|
||||
const fileWithoutGps = await stripGpsFromFile(fileBytes);
|
||||
console.log('Uploading file without GPS');
|
||||
return putFile(fileWithoutGps, photoPath).then(async url => {
|
||||
if (url) {
|
||||
|
||||
@ -1,24 +1,26 @@
|
||||
import * as PiExif from 'piexifjs';
|
||||
// import * as PiExif from 'piexifjs';
|
||||
import { b64toBlob } from './data';
|
||||
import { removeGpsData } from '@/photo/server';
|
||||
|
||||
export const stripGpsFromFile = (
|
||||
export const stripGpsFromFile = async (
|
||||
fileBytes: ArrayBuffer
|
||||
): Blob => {
|
||||
const base64 = Buffer.from(fileBytes).toString('base64');
|
||||
const base64Url = `data:image/jpeg;base64,${base64}`;
|
||||
): Promise<Blob> => {
|
||||
// const base64 = Buffer.from(fileBytes).toString('base64');
|
||||
// const base64Url = `data:image/jpeg;base64,${base64}`;
|
||||
|
||||
console.log('Stripping GPS from file');
|
||||
const exifObject = PiExif.load(base64Url);
|
||||
delete exifObject.GPS;
|
||||
const exifDataWithoutGps = PiExif.dump(exifObject);
|
||||
// console.log('Stripping GPS from file');
|
||||
// const exifObject = PiExif.load(base64Url);
|
||||
// delete exifObject.GPS;
|
||||
// const exifDataWithoutGps = PiExif.dump(exifObject);
|
||||
|
||||
console.log('Updating EXIF');
|
||||
const data = PiExif.insert(
|
||||
exifDataWithoutGps,
|
||||
base64Url,
|
||||
);
|
||||
// console.log('Updating EXIF');
|
||||
// const data = PiExif.insert(
|
||||
// exifDataWithoutGps,
|
||||
// base64Url,
|
||||
// );
|
||||
|
||||
console.log('EXIF updated');
|
||||
// console.log('EXIF updated');
|
||||
|
||||
return b64toBlob(data);
|
||||
// Removing EXIF data with Sharp
|
||||
return b64toBlob(await removeGpsData(fileBytes));
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user