|
|
@ -118,24 +118,25 @@ const loadImage = (inputFile: File) => new Promise<HTMLImageElement>((resolve, r
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Get the exif orientation for the image. */
|
|
|
|
/** Get the exif orientation for the image. */
|
|
|
|
const getOrientation = (img: HTMLImageElement, type = 'image/png') => new Promise<number>(resolve => {
|
|
|
|
async function getOrientation(img: HTMLImageElement, type = 'image/png'): Promise<number> {
|
|
|
|
if (!['image/jpeg', 'image/webp'].includes(type)) {
|
|
|
|
if (!['image/jpeg', 'image/webp'].includes(type)) {
|
|
|
|
resolve(1);
|
|
|
|
return 1;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
import('exif-js').then(({ default: EXIF }) => {
|
|
|
|
try {
|
|
|
|
// @ts-ignore: The TypeScript definition is wrong.
|
|
|
|
const exifr = await import('exifr');
|
|
|
|
EXIF.getData(img, () => {
|
|
|
|
const orientation = await exifr.orientation(img) ?? 1;
|
|
|
|
const orientation = EXIF.getTag(img, 'Orientation');
|
|
|
|
|
|
|
|
if (orientation !== 1) {
|
|
|
|
if (orientation !== 1) {
|
|
|
|
dropOrientationIfNeeded(orientation).then(resolve).catch(() => resolve(orientation));
|
|
|
|
return await dropOrientationIfNeeded(orientation);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
resolve(orientation);
|
|
|
|
return orientation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
}).catch(() => {});
|
|
|
|
console.error('Failed to get orientation:', error);
|
|
|
|
});
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const processImage = (
|
|
|
|
const processImage = (
|
|
|
|
img: HTMLImageElement,
|
|
|
|
img: HTMLImageElement,
|
|
|
|