diff --git a/src/photo/server.ts b/src/photo/server.ts index 2b897cf5..a6056afc 100644 --- a/src/photo/server.ts +++ b/src/photo/server.ts @@ -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: '', + }, + }) + ); diff --git a/src/photo/storage.ts b/src/photo/storage.ts index c2ec1d8d..908cd168 100644 --- a/src/photo/storage.ts +++ b/src/photo/storage.ts @@ -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) { diff --git a/src/utility/exif-server.ts b/src/utility/exif-server.ts index 47994651..4931e57b 100644 --- a/src/utility/exif-server.ts +++ b/src/utility/exif-server.ts @@ -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 => { + // 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)); };