kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'exif-fix' into 'develop'
Swap out exif-js for exifr Closes #1519 See merge request soapbox-pub/soapbox!2701environments/review-main-yi2y9f/deployments/3909
commit
9f15991ab5
|
@ -118,24 +118,25 @@ const loadImage = (inputFile: File) => new Promise<HTMLImageElement>((resolve, r
|
|||
});
|
||||
|
||||
/** 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)) {
|
||||
resolve(1);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
import('exif-js').then(({ default: EXIF }) => {
|
||||
// @ts-ignore: The TypeScript definition is wrong.
|
||||
EXIF.getData(img, () => {
|
||||
const orientation = EXIF.getTag(img, 'Orientation');
|
||||
if (orientation !== 1) {
|
||||
dropOrientationIfNeeded(orientation).then(resolve).catch(() => resolve(orientation));
|
||||
} else {
|
||||
resolve(orientation);
|
||||
}
|
||||
});
|
||||
}).catch(() => {});
|
||||
});
|
||||
try {
|
||||
const exifr = await import('exifr');
|
||||
const orientation = await exifr.orientation(img) ?? 1;
|
||||
|
||||
if (orientation !== 1) {
|
||||
return await dropOrientationIfNeeded(orientation);
|
||||
} else {
|
||||
return orientation;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to get orientation:', error);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const processImage = (
|
||||
img: HTMLImageElement,
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
"emoji-datasource": "14.0.0",
|
||||
"emoji-mart": "^5.5.2",
|
||||
"escape-html": "^1.0.3",
|
||||
"exif-js": "^2.3.0",
|
||||
"exifr": "^7.1.3",
|
||||
"graphemesplit": "^2.4.4",
|
||||
"http-link-header": "^1.0.2",
|
||||
"immer": "^9.0.19",
|
||||
|
|
|
@ -4778,10 +4778,10 @@ exenv@^1.2.2:
|
|||
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
|
||||
integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50=
|
||||
|
||||
exif-js@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/exif-js/-/exif-js-2.3.0.tgz#9d10819bf571f873813e7640241255ab9ce1a814"
|
||||
integrity sha1-nRCBm/Vx+HOBPnZAJBJVq5zhqBQ=
|
||||
exifr@^7.1.3:
|
||||
version "7.1.3"
|
||||
resolved "https://registry.yarnpkg.com/exifr/-/exifr-7.1.3.tgz#f6218012c36dbb7d843222011b27f065fddbab6f"
|
||||
integrity sha512-g/aje2noHivrRSLbAUtBPWFbxKdKhgj/xr1vATDdUXPOFYJlQ62Ft0oy+72V6XLIpDJfHs6gXLbBLAolqOXYRw==
|
||||
|
||||
expand-tilde@^2.0.2:
|
||||
version "2.0.2"
|
||||
|
|
Ładowanie…
Reference in New Issue