Remove exifr dependency
This commit is contained in:
parent
d9fb484471
commit
cbb74059b3
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -17,7 +17,6 @@
|
|||||||
"depluralizes",
|
"depluralizes",
|
||||||
"Eterna",
|
"Eterna",
|
||||||
"exif",
|
"exif",
|
||||||
"exifr",
|
|
||||||
"exiftool",
|
"exiftool",
|
||||||
"favicons",
|
"favicons",
|
||||||
"favs",
|
"favs",
|
||||||
|
|||||||
@ -26,7 +26,6 @@
|
|||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"date-fns-tz": "^3.2.0",
|
"date-fns-tz": "^3.2.0",
|
||||||
"exifr": "^7.1.3",
|
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"framer-motion": "^12.5.0",
|
"framer-motion": "^12.5.0",
|
||||||
"nanoid": "^5.1.5",
|
"nanoid": "^5.1.5",
|
||||||
|
|||||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -59,9 +59,6 @@ importers:
|
|||||||
date-fns-tz:
|
date-fns-tz:
|
||||||
specifier: ^3.2.0
|
specifier: ^3.2.0
|
||||||
version: 3.2.0(date-fns@4.1.0)
|
version: 3.2.0(date-fns@4.1.0)
|
||||||
exifr:
|
|
||||||
specifier: ^7.1.3
|
|
||||||
version: 7.1.3
|
|
||||||
fast-deep-equal:
|
fast-deep-equal:
|
||||||
specifier: ^3.1.3
|
specifier: ^3.1.3
|
||||||
version: 3.1.3
|
version: 3.1.3
|
||||||
@ -2469,9 +2466,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==}
|
resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
exifr@7.1.3:
|
|
||||||
resolution: {integrity: sha512-g/aje2noHivrRSLbAUtBPWFbxKdKhgj/xr1vATDdUXPOFYJlQ62Ft0oy+72V6XLIpDJfHs6gXLbBLAolqOXYRw==}
|
|
||||||
|
|
||||||
exit@0.1.2:
|
exit@0.1.2:
|
||||||
resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==}
|
resolution: {integrity: sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==}
|
||||||
engines: {node: '>= 0.8.0'}
|
engines: {node: '>= 0.8.0'}
|
||||||
@ -7229,8 +7223,6 @@ snapshots:
|
|||||||
signal-exit: 3.0.7
|
signal-exit: 3.0.7
|
||||||
strip-final-newline: 2.0.0
|
strip-final-newline: 2.0.0
|
||||||
|
|
||||||
exifr@7.1.3: {}
|
|
||||||
|
|
||||||
exit@0.1.2: {}
|
exit@0.1.2: {}
|
||||||
|
|
||||||
expect@29.7.0:
|
expect@29.7.0:
|
||||||
|
|||||||
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
import { blobToImage } from '@/utility/blob';
|
import { blobToImage } from '@/utility/blob';
|
||||||
import { useRef, RefObject } from 'react';
|
import { useRef, RefObject } from 'react';
|
||||||
import { CopyExif } from '@/utility/exif';
|
import { CopyExif, getOrientation } from '@/utility/exif';
|
||||||
import exifr from 'exifr';
|
|
||||||
import { clsx } from 'clsx/lite';
|
import { clsx } from 'clsx/lite';
|
||||||
import { ACCEPTED_PHOTO_FILE_TYPES } from '@/photo';
|
import { ACCEPTED_PHOTO_FILE_TYPES } from '@/photo';
|
||||||
import { FiUploadCloud } from 'react-icons/fi';
|
import { FiUploadCloud } from 'react-icons/fi';
|
||||||
@ -131,8 +130,7 @@ export default function ImageInput({
|
|||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
|
||||||
let orientation = await exifr
|
let orientation = await getOrientation(file)
|
||||||
.orientation(file)
|
|
||||||
.catch(() => 1) ?? 1;
|
.catch(() => 1) ?? 1;
|
||||||
|
|
||||||
// Preserve EXIF data for PNGs
|
// Preserve EXIF data for PNGs
|
||||||
|
|||||||
@ -124,3 +124,40 @@ export const CopyExif = async (
|
|||||||
return new Blob([dest.slice(0, 2), exif, dest.slice(2)], { type });
|
return new Blob([dest.slice(0, 2), exif, dest.slice(2)], { type });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getOrientation = (file: File): Promise<number> =>
|
||||||
|
file.arrayBuffer().then(buffer => {
|
||||||
|
const view = new DataView(buffer);
|
||||||
|
|
||||||
|
if (view.getUint16(0, false) !== 0xFFD8) {
|
||||||
|
return -2;
|
||||||
|
} else {
|
||||||
|
const length = view.byteLength;
|
||||||
|
let offset = 2;
|
||||||
|
while (offset < length) {
|
||||||
|
if (view.getUint16(offset + 2, false) <= 8) return -1;
|
||||||
|
const marker = view.getUint16(offset, false);
|
||||||
|
offset += 2;
|
||||||
|
if (marker === 0xFFE1) {
|
||||||
|
if (view.getUint32(offset += 2, false) !== 0x45786966) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
const little = view.getUint16(offset += 6, false) === 0x4949;
|
||||||
|
offset += view.getUint32(offset + 4, little);
|
||||||
|
const tags = view.getUint16(offset, little);
|
||||||
|
offset += 2;
|
||||||
|
for (let i = 0; i < tags; i++) {
|
||||||
|
if (view.getUint16(offset + (i * 12), little) === 0x0112) {
|
||||||
|
return view.getUint16(offset + (i * 12) + 8, little);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((marker & 0xFF00) !== 0xFF00) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
offset += view.getUint16(offset, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user