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))
|
fetch(decodeURIComponent(url))
|
||||||
.then(res => res.arrayBuffer())
|
.then(res => res.arrayBuffer())
|
||||||
.then(buffer => blurImage(buffer));
|
.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');
|
console.log('Fetching original file');
|
||||||
const fileBytes = await fetch(urlOrigin, { cache: 'no-store' })
|
const fileBytes = await fetch(urlOrigin, { cache: 'no-store' })
|
||||||
.then(res => res.arrayBuffer());
|
.then(res => res.arrayBuffer());
|
||||||
const fileWithoutGps = stripGpsFromFile(fileBytes);
|
const fileWithoutGps = await stripGpsFromFile(fileBytes);
|
||||||
console.log('Uploading file without GPS');
|
console.log('Uploading file without GPS');
|
||||||
return putFile(fileWithoutGps, photoPath).then(async url => {
|
return putFile(fileWithoutGps, photoPath).then(async url => {
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|||||||
@ -1,24 +1,26 @@
|
|||||||
import * as PiExif from 'piexifjs';
|
// import * as PiExif from 'piexifjs';
|
||||||
import { b64toBlob } from './data';
|
import { b64toBlob } from './data';
|
||||||
|
import { removeGpsData } from '@/photo/server';
|
||||||
|
|
||||||
export const stripGpsFromFile = (
|
export const stripGpsFromFile = async (
|
||||||
fileBytes: ArrayBuffer
|
fileBytes: ArrayBuffer
|
||||||
): Blob => {
|
): Promise<Blob> => {
|
||||||
const base64 = Buffer.from(fileBytes).toString('base64');
|
// const base64 = Buffer.from(fileBytes).toString('base64');
|
||||||
const base64Url = `data:image/jpeg;base64,${base64}`;
|
// const base64Url = `data:image/jpeg;base64,${base64}`;
|
||||||
|
|
||||||
console.log('Stripping GPS from file');
|
// console.log('Stripping GPS from file');
|
||||||
const exifObject = PiExif.load(base64Url);
|
// const exifObject = PiExif.load(base64Url);
|
||||||
delete exifObject.GPS;
|
// delete exifObject.GPS;
|
||||||
const exifDataWithoutGps = PiExif.dump(exifObject);
|
// const exifDataWithoutGps = PiExif.dump(exifObject);
|
||||||
|
|
||||||
console.log('Updating EXIF');
|
// console.log('Updating EXIF');
|
||||||
const data = PiExif.insert(
|
// const data = PiExif.insert(
|
||||||
exifDataWithoutGps,
|
// exifDataWithoutGps,
|
||||||
base64Url,
|
// 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